Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^2: Help with PHP-to-Perl CPAN bundle

by castaway (Parson)
on Sep 29, 2004 at 07:03 UTC ( [id://394875]=note: print w/replies, xml ) Need Help??

in reply to Re: Help with PHP-to-Perl CPAN bundle
in thread Help with PHP-to-Perl CPAN bundle

foreach my $alias (@array) creates an alias to the @array entry. Mutiple aliases in the loop aren't possible. (In PHP you can do for ($hash => $key, $value) {...} to do multiple aliases)
Unless I'm misunderstanding this (not knowing PHP), then what you are looking for here is each. eg:
while (my ($key, $value) = each %hash ) { .. }
Or am I way off the mark?


Replies are listed 'Best First'.
Re^3: Help with PHP-to-Perl CPAN bundle
by erikharrison (Deacon) on Sep 30, 2004 at 15:05 UTC
    $key, $value are copies of the values in the hash. The => operator can be used in PHP to create aliases to the elements, so changing $value is the same as changing $hash{$key} (to use Perlish syntax). So, in PHP:
    $array = (0,1,2,3,4,5); for ($array => $a, $b, $c) { $c = 'two'; } print ($array[2]) #Prints 'two'

    Light a man a fire, he's warm for a day. Catch a man on fire, and he's warm for the rest of his life. - Terry Pratchet

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://394875]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-05-25 02:14 GMT
Find Nodes?
    Voting Booth?

    No recent polls found