accessing a hash made by iCal::Parser
accessing a hash made by iCal::Parser
am 06.02.2006 17:16:38 von lars
I'm experimenting with the output from the iCal::Parser module, but am a
bit rusty on accessing parts of the a. How would I access part of a
hash, or a hash of a hash of a hash, say of the part with the key 'URL'
shown below?
I know that iCal::Parser is reading and parsing a file, because
these lines:
my $ical_parser=iCal::Parser->new();
my $ical = $ical_parser->parse($file);
print Dumper($ical); # from Data::Dumper
produce this result:
$VAR1 = {
'todos' => [],
'events' => {
'2006' => {
'6' => {
'8' => {
'uuid:1138718551530' => {
'URL' => 'http://www-ict.ewi.tudelft.nl/~wic2006/',
... and so on ...
However, this following is apparently the wrong way to try to read a leaf
on the tree. What's the right way?
print $ical=>{'events'}=>{'2006'}=>{'6'}=>\
{'8'}=>{'uuid:1138718551530'}=>{'URL'};
Instead of giving me the desired 'http://www-ict.ewi.tudelft.nl/~wic2006/'
as shown above, it gives this:
HASH(0x18895f8)HASH(0x19e7624)HASH(0x19e7648)HASH(0x19e7660) \
HASH(0x19e76a8)HASH(0x19e76d8)HASH(0x19e76cc)
--
Lars
Software patents harm all Net-based business, write your MEP:
http://wwwdb.europarl.eu.int/ep6/owa/p_meps2.repartition?ilg =EN
Re: accessing a hash made by iCal::Parser
am 06.02.2006 18:55:53 von Paul Lalli
lars@nospam.nosoftwarepatents.edu wrote:
> However, this following is apparently the wrong way to try to read a leaf
> on the tree. What's the right way?
> print $ical=>{'events'}=>{'2006'}=>{'6'}=>{'8'}=>{'uuid:1138718551 530'}=>{'URL'};
Where did you get the idea that => should be used to access elements of
a hash? They are used to *create* key/value pairs when defining a
hash. The => is nothing more than a comma, with a tiny bit of magic
thrown in. Read about it in perldoc perlop.
Read about how to access elements of a hash to which you only have a
reference in:
perldoc perlreftut
perldoc perllol
perldoc perldsc
perldoc perlref
Paul Lalli
Re: accessing a hash made by iCal::Parser
am 06.02.2006 21:12:40 von lars
Paul Lalli wrote:
: Where did you get the idea that => should be used to access elements of
: a hash?
From about 3 years with no scripting to forget perl syntax.
: They are used to *create* key/value pairs when defining a
: hash. The => is nothing more than a comma, with a tiny bit of magic
: thrown in. Read about it in perldoc perlop.
Not exactly a solution, but it jogs my memory. Creation and reference
don't use the same syntax. Thanks.
--
Lars
Software patents harm all Net-based business, write your MEP:
http://wwwdb.europarl.eu.int/ep6/owa/p_meps2.repartition?ilg =EN
Re: accessing a hash made by iCal::Parser
am 07.02.2006 00:32:42 von unknown
lars@nospam.nosoftwarepatents.edu wrote:
> I'm experimenting with the output from the iCal::Parser module, but am a
> bit rusty on accessing parts of the a. How would I access part of a
> hash, or a hash of a hash of a hash, say of the part with the key 'URL'
> shown below?
>
> I know that iCal::Parser is reading and parsing a file, because
> these lines:
>
> my $ical_parser=iCal::Parser->new();
> my $ical = $ical_parser->parse($file);
> print Dumper($ical); # from Data::Dumper
>
> produce this result:
> $VAR1 = {
> 'todos' => [],
> 'events' => {
> '2006' => {
> '6' => {
> '8' => {
> 'uuid:1138718551530' => {
> 'URL' => 'http://www-ict.ewi.tudelft.nl/~wic2006/',
> ... and so on ...
>
> However, this following is apparently the wrong way to try to read a leaf
> on the tree. What's the right way?
> print $ical=>{'events'}=>{'2006'}=>{'6'}=>\
> {'8'}=>{'uuid:1138718551530'}=>{'URL'};
print $ical->{events}{2006}{6}{8}{'uuid:...'}{URL};
>
> Instead of giving me the desired 'http://www-ict.ewi.tudelft.nl/~wic2006/'
> as shown above, it gives this:
> HASH(0x18895f8)HASH(0x19e7624)HASH(0x19e7648)HASH(0x19e7660) \
> HASH(0x19e76a8)HASH(0x19e76d8)HASH(0x19e76cc)
Basically, you needed '->' (which is the dereference operator) rather
than '=>' (which is a glorified comma). All that was really needed was
s/=>/->/g, though Perl allows you to omit the dereference operators
between the hash keys. It also lets you omit the quotes around the hash
key if the key matches \w.
This might better have been posted over in comp.lang.perl.misc, since it
wasn't really anything to do with any of the modules.
Tom Wyant
Re: accessing a hash made by iCal::Parser
am 07.02.2006 15:52:21 von lars
harryfmudd [AT] comcast [DOT] net <"harryfmudd [AT] comcast [DOT] net"> wrote:
: This might better have been posted over in comp.lang.perl.misc, since it
: wasn't really anything to do with any of the modules.
I'll make sure it's in my newsreader. Thanks.
--
Lars
Software patents harm all Net-based business, write your MEP:
http://wwwdb.europarl.eu.int/ep6/owa/p_meps2.repartition?ilg =EN