Silly Newbie questions

Discussion in 'Perl Misc' started by Cerveza Mas Fina, Jan 17, 2007.

  1. Hi
    I have two questions
    1) I found this line of code in a book
    foreach $item ( @{ $rss->{ 'items'} })
    {
    print $item->{'title'}
    }

    I cant quite figure out what the @{ blah } is doing to a hash
    reference,

    2) I have seen a lot of perl code like $xx = shift;
    What does this mean ? what purpose does that server ?

    I shall appreciate any answers.
     
    Cerveza Mas Fina, Jan 17, 2007
    #1
    1. Advertising

  2. Cerveza Mas Fina

    Guest

    Cerveza Mas Fina wrote:
    > foreach $item ( @{ $rss->{ 'items'} })


    The value of $rss{'items'} is (apparently) an array reference (not a
    hash reference - it's a hash value but it's an array reference). This
    would be a "hash of arrays" (HoA).

    Consider:

    $hash{'numbers'} = [1, 2, 3];
    print "$_\n" for @{ $hash{'numbers'} };

    is really the same as:

    my $array_ref = [1, 2, 3];
    print "$_\n" for @{ $array_ref };

    > 2) I have seen a lot of perl code like $xx = shift;
    > What does this mean ? what purpose does that server ?


    perldoc -f shift

    --
    David Filmer (http://DavidFilmer.com)
     
    , Jan 17, 2007
    #2
    1. Advertising

  3. On 01/16/2007 11:31 PM, Cerveza Mas Fina wrote:
    > Hi
    > I have two questions
    > 1) I found this line of code in a book
    > foreach $item ( @{ $rss->{ 'items'} })
    > {
    > print $item->{'title'}
    > }
    >
    > I cant quite figure out what the @{ blah } is doing to a hash
    > reference,
    >


    Evidently, $rss->{items} is a hash entry that contains an array
    reference. Consider this example:

    my $item;
    my $rss = { items => ['orange', 'banana', 'apricot'] };
    foreach $item ( @{ $rss->{items} } ) {
    print "\$item = $item\n";
    }

    You should learn to read the Perl documentation:
    Start->Run->"perldoc perl"
    Start->Run->"perldoc perldsc"

    > 2) I have seen a lot of perl code like $xx = shift;
    > What does this mean ? what purpose does that server ?
    >
    > I shall appreciate any answers.
    >


    Start->Run->"perldoc -f shift"
    Start->Run->"perldoc perldoc"


    HTH


    --
    Windows Vista and your freedom in conflict:
    http://techdirt.com/articles/20061019/102225.shtml
     
    Mumia W. (NOSPAM), Jan 17, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bill ramsay

    two silly questions

    bill ramsay, Jun 3, 2004, in forum: Python
    Replies:
    3
    Views:
    327
    bill ramsay
    Jun 4, 2004
  2. drs
    Replies:
    3
    Views:
    416
    Steven Bethard
    Dec 20, 2004
  3. Gus Gassmann
    Replies:
    3
    Views:
    458
    Martin Honnen
    Sep 20, 2007
  4. phaeton

    My two questions. One legit, one silly...

    phaeton, Dec 27, 2011, in forum: C Programming
    Replies:
    5
    Views:
    316
    /dev/phaeton
    Dec 29, 2011
  5. GGarramuno
    Replies:
    1
    Views:
    131
    Eric Hodel
    Dec 30, 2003
Loading...

Share This Page