in reply to reading file in Hash
Do like this way also
use strict; use warnings; use Data::Dumper; open FH, "file", or die "Cannot open \$data $!"; my ( @headers, %hash, @arr ); while(<FH>){ chomp; if($.==1){ @arr=split /\s+/,$_; foreach(@arr){ $hash{$_}=[]; } } else{ my @temp=split /\s+/,$_; my $i=0; foreach(@temp){ push @{$hash{$arr[$i++]}},$_; } } } print Dumper \%hash;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: reading file in Hash
by Anonymous Monk on May 07, 2009 at 08:31 UTC |