[Israel.pm] Another newbie question - Hashes

Yuval Yaari yuval at windax.com
Tue Feb 3 07:08:29 PST 2004


## UNTESTED ##
open(FILE, "file") or die "cannot open file: $!";
my @lines = <FILE>;
close(FILE);
chomp(@lines);

my %hash = ();

foreach my $line (@lines) {
    my ($key, $value) = split(/\s+/, $line);
    $hash{$key} = $value;
}
__END__

how about that?

Prager, Mark wrote:

>I am trying to read in input file into a hash -
>i.e 
>File:
>3 a
>4 ssd
>5 fg
>67 aa
>654 lp
>
>would go into a hash indexed by the first column.
>
>I know we did this in the course - but for the life of me, I cannot find it in my
>notes..
>
>
>Best Regards,
>
>Mark Prager
>I & T Engineer, Project Delivery
>Binyan Mercazim, Room 508
>NDS Technologies Israel Ltd.
>
>
>5A Hamarpe Street
>Har Hotzvim PO BOX 23012
>Jerusalem 912235 Israel
>Tel:+ 972-2-589-4264
>Mob:+ 972-55-66-4264
>Fax:+ 972-2-589-4725
>Url: http://www2.ozin.com/mark
>mailto:mprager at ndsisrael.com 
>***********************************************************************************
>Information contained in this email message is intended only for use of the individual or entity named above. If the reader of this message is not the intended recipient, or the employee or agent responsible to deliver it to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the postmaster at ndsisrael.com and destroy the original message.
>***********************************************************************************
>
>_______________________________________________
>Perl mailing list
>Perl at perl.org.il
>http://www.perl.org.il/mailman/listinfo/perl
>
>YAPC::Israel::2004
>http://www.perl.org.il/YAPC/2004/
>
>
>  
>




More information about the Perl mailing list