Professional Web Applications Themes

accessing a hash made by iCal::Pr - PERL Modules

I'm experimenting with the output from the iCal::Pr 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::Pr is reading and parsing a file, because these lines: my $ical_pr=iCal::Pr->new(); my $ical = $ical_pr->p($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 ...

  1. #1

    Default accessing a hash made by iCal::Pr

    I'm experimenting with the output from the iCal::Pr 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::Pr is reading and parsing a file, because
    these lines:

    my $ical_pr=iCal::Pr->new();
    my $ical = $ical_pr->p($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:
    [url]http://wwwdb.europarl.eu.int/ep6/owa/p_meps2.repartition?ilg=EN[/url]
    lars@nospam.nosoftwarepatents.edu Guest

  2. #2

    Default Re: accessing a hash made by iCal::Pr

    [email]larsnospam.nosoftwarepatents.edu[/email] 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: 1138718551530'}=>{'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

    Paul Lalli Guest

  3. #3

    Default Re: accessing a hash made by iCal::Pr

    Paul Lalli <mritty> 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:
    [url]http://wwwdb.europarl.eu.int/ep6/owa/p_meps2.repartition?ilg=EN[/url]
    lars@nospam.nosoftwarepatents.edu Guest

  4. #4

    Default Re: accessing a hash made by iCal::Pr

    [email]larsnospam.nosoftwarepatents.edu[/email] wrote:
    > I'm experimenting with the output from the iCal::Pr 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::Pr is reading and parsing a file, because
    > these lines:
    >
    > my $ical_pr=iCal::Pr->new();
    > my $ical = $ical_pr->p($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
    harryfmudd [AT] comcast [DOT] net Guest

  5. #5

    Default Re: accessing a hash made by iCal::Pr

    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:
    [url]http://wwwdb.europarl.eu.int/ep6/owa/p_meps2.repartition?ilg=EN[/url]
    lars@nospam.nosoftwarepatents.edu Guest

Similar Threads

  1. Importing iCal files
    By michaelmuller in forum Macromedia ColdFusion
    Replies: 0
    Last Post: March 15th, 05:08 PM
  2. Sort a hash based on values in the hash stored as arrays of hashes
    By Tore Aursand in forum PERL Miscellaneous
    Replies: 3
    Last Post: September 16th, 10:14 AM
  3. i need help accessing a hash
    By Jerry Preston in forum PERL Beginners
    Replies: 3
    Last Post: August 17th, 01:54 PM
  4. Another reference question (hash of hash references)
    By Tim Musson in forum PERL Beginners
    Replies: 2
    Last Post: August 8th, 01:11 PM
  5. isync - T68i mobile phone bluetooth - ical failure
    By Nick Prince in forum Mac Applications & Software
    Replies: 3
    Last Post: July 22nd, 05:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139