in reply to split to hash, problem with random keys
Test1|Test2|Test3 Foo1|Foo2|Foo3Code
use strict;
my @records;
my @keys = qw(FirstKey SecondKey ThirdKey);
sub getkey()
{
my $ret = shift @keys;
push @keys, $ret;
return $ret;
}
open IN, "<test.txt";
while(<IN>)
{
my %record;
map{$record{getkey()}=$_} split(/\|/) ;
push(@records,\%record);
}
foreach my $rec (@records)
{
my %thing = %{$rec};
foreach my $key (@keys)
{
print "$key: $thing{$key}\n";
}
}
--
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: split to hash, problem with random keys
by december (Pilgrim) on Jul 04, 2003 at 13:47 UTC |