Click here to get back home

accessing a hash made by iCal::Parser

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
accessing a hash made by iCal::Parser lars 02-06-2006
Posted by lars on February 6, 2006, 11:16 am
Please log in for more thread options


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=>=>=>=>\
         =>=>;

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

Posted by Paul Lalli on February 6, 2006, 12:55 pm
Please log in for more thread options


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=>=>=>=>=>=>;

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


Posted by lars on February 6, 2006, 3:12 pm
Please log in for more thread options


: 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

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

Posted by lars on February 7, 2006, 9:52 am
Please log in for more thread options


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

Similar ThreadsPosted
Modules for hash functions? (ie, common algorithms for computing hash keys, not manipulating perl hashes) August 26, 2006, 7:08 pm
Accessing the Memoize cache April 2, 2005, 1:15 am
Accessing listbox using perl? May 16, 2007, 7:48 pm
SSH Modules: Accessing CLI box using SSH and not getting the return output?? November 12, 2006, 11:48 pm
Problem in accessing DLL function from perl module. July 31, 2007, 4:52 am
SOAP::WSDL error accessing remote site. July 19, 2007, 3:14 am
Hash July 14, 2006, 5:27 pm
Is a hash the best method to do this? December 24, 2007, 1:23 pm
What can you use to tie a hash of hashes to either dbm or ascii? December 2, 2007, 12:26 pm
Options for passing Hash to a subroutine. March 30, 2005, 7:39 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap