Silly Newbie questions

C

Cerveza Mas Fina

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.
 
U

usenet

Cerveza said:
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
 
G

Guest

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top