Quite easily:
open(IN,$file) || die "could not open $file: $!\n";
while (<IN>)
{
s:#.*$::; # weed out comments
next unless /\S/; # make sure there's something to input
($from,$to)=split /\s+/; # split the line by the whitespace
$hash{$from}=$to;
}
close IN;
As long as you don't have any whitespace at the beginning of your lines and each name
is exactly one word, then this will work.
-----Original Message-----
From: James Ferree [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 08, 2001 10:57 AM
To: [EMAIL PROTECTED]
Subject: Loading file into hash
Hi,
I am looking for a way to load a file containing the
following example data into a hash
#From TO
Jim James
Art Arthur
John Arthur
Then when $a=Jim I would like to convert it to
$a=James.
Can this be done?
Jim
__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]