Hi,

Though this thread is now almost a week old, I thought I'd offer one more
suggestion.  How about using this

     %people = map { chomp; split } <INPUT>;

in place of 

     %people =  <INPUT>;


To my eyes, it is cleaner than adding an explicit loop.

TMTOWTDI,
Jeff


-----Original Message-----
From: Jose Malacara [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 14, 2002 2:35 AM
To: Perl beginners
Subject: open file into hash


Hello. I was wondering if there was a way to open a file into a hash? I know

this works for arrays, but was wondering if I this could be done for a hash 
also.

I have a file called people.data, which contains two colums:
jose            2
karen           8
jason           9
tracey  1


Can someone tell me what I am doing wrong here:
=============================================
#! /usr/bin/perl -w

open (INPUT, "<people.data");
%people = <INPUT>;
close (INPUT);

#%people = (
#        "jose" => '2',
#        "karen" => '8',
#        "jason" => '9',
#        "tracey" => '1'
#);

print "The value for jose is $people{jose}\n";
=============================================

I expect to return the value of "2", but see the following error instead:

"Use of uninitialized value in concatenation (.) or string at ./new.pl line 
14.
The value for jose is"


I am guessing that this is related to opening the filehandle as it works if
I 
declare the hash within the script (commented out above).

Any help would be greatly appreciated.

Jose

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to