Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Referncing a local array outside

by edoc (Chaplain)
on Dec 16, 2003 at 13:49 UTC ( [id://315057]=note: print w/replies, xml ) Need Help??


in reply to Referncing a local array outside

you could ditch the temporary variable altogether..

#!/usr/bin/perl use strict; my %alink; # Create some arrays of random numbers... foreach my $name ('Fred', 'Barney', 'Wilma', 'Peggy'){ for (my $i = 0; $i < 5; $i++){ push( @{$alink{$name}}, int(rand(30)) ); } } foreach my $key (keys %alink){ foreach my $element ( @{$alink{$key}} ){ print $key,' ',$element,"\n"; } }

(also added 'use strict;' and then 'my' declarations as required.)

cheers,

J

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-24 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found