Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Making a hash of arrays from a while loop

by wfsp (Abbot)
on Mar 04, 2008 at 12:40 UTC ( #671862=note: print w/replies, xml ) Need Help??


in reply to Re^2: Making a hash of arrays from a while loop
in thread Making a hash of arrays from a while loop

Or declare @array within the while loop. This avoids making a copy of the array to make the anonymous reference.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 1; my %hash; while (my $rec = <DATA>){ chomp $rec; # declare the array my ($key, @array) = split(/ /, $rec, 2); $hash{$key} = \@array; } print Dumper \%hash; __DATA__ 1 2 3 4 5 6 7 8
$VAR1 = { '1' => [ '2 3 4' ], '5' => [ '6 7 8' ] };

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2023-09-27 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?