[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Get info out a JSON file



That's right.  This is Perl's textual representation of an internal data
structure - in this case, a hash of hashes (hashes are associative
arrays).  In Perl, the => character is essentially identical to a
comma.  It's a bit of syntactic sugar whose purpose is to indicate to
the reader (ie, you) that the two elements are not just a simple
2-element list, but a key/value pair.  Combined with the Data::Dumper
module's pretty formatting, it becomes more clear that this is a list of
key/value pairs.

Here - notice that you can arbitrarily replace commas with => and
vice-versa, but things will still work just fine:

sauer@trogdor:~$ perl -le '@a=(1 => 2 => 3 => 4); print scalar @a; print
$a[1]'
4
2
sauer@trogdor:~$ perl -le '%a=(1 , "a" => 2 , "b"); print $a{2}'
b
sauer@trogdor:~$ perl -le '%a=(1 => "a" , 2 => "b"); print $a{2}'
b


And by "work fine" I of course mean "work fine until someone has to
maintain your code, but decides it'd be more productive to smash your
skull". :)

--Danny

PS - sorry if there are two messages sent.  I just got a new laptop, and
the keys are laid out differently from my old keyboard.  I'm not sure if
Thunderbird sent the other message or discarded it...

PPS - the HP G60 line of laptops apparently are well supported (webcam,
wireless, sound, pointer, wireless disable button, audio via HDMI port)
out of the box by Ubuntu 9.10

Samir Faci wrote:
> Actually yes, that doesn't look like JSON code, the => isn't part of
> the standard JSON notation.
>   

-
To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.