Perl is line oriented by default
Use the <FILE_HANDLE> construct.
While Ben will do this in one line, here is
how I would handle it.
If you NEED to open the file (rather than STDIN):
\nuse strict;\nopen (IN,"file.dat") or die "Can't open file - $!";\nmy %hash;\nwhile (<IN>){\n chomp;\n my ($key,$data) = split(' ',$_,2);\n $hash{$key} = $data;\n}\nclose (IN);\n
Edited by
broomberg
Sept. 14, 2004, 12:10:08 AM EDT
Perl is line oriented by default
Use the <FILE_HANDLE> construct.
While Ben will do this in one line, here is
how I would handle it.
If you NEED to open the file (rather than STDIN):
use strict;
open (IN,"file.dat") or die "Can't open file - $!";
my $hash;
while (<IN>){
chomp;
my ($key,$data) = split(' ',$_,2);
$hash{$key} = $data;
}
close (IN);