|
Posted by harryfmudd [AT] comcast [DOT] on February 6, 2006, 6:32 pm
Please log in for more thread options
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=>=>=>=>\
> =>=>;
print $ical->;
>
> 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
|