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
#!/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' ] };
|
|---|