develooper Front page | perl.beginners | Postings from September 2008

while loops and the bedlam of the hash key

Thread Next
From:
frazzmata
Date:
September 5, 2008 03:43
Subject:
while loops and the bedlam of the hash key

I have a problem
I am trying to take lines in a text file that look like this. although
there are 500 more or so (and they have more realistic names)

25727   dude, some   M MEX.AMER.  DORM1
25797   dude, other     M BLACK      DORM2
29291   guy, random    M BLACK      DORM3
30249   fella, helluva   M BLACK      DORM4
31139A  brother, notmy   M CAUC       DORM5

Which is essentially, a student Id, last, first, sex, race, etc…..

I am trying to use the following code to make the student id the key
and the whole line the value (including the student ID that I am using
as the key)

So, an example would look like this on paper

       Key:                                    Value:
$student{25727} =                 25727   dude, some   M MEX.AMER.
DORM1

And so on

This is the code I’ve tried…

my %longz;

while (<IFILE>) {
    chomp;
	($ya,$rest) = split(/^\s+/,$_);
     $longz{$ya} = $rest;
      }


My hope is to create a hash that I can use the student ids from
another list, and if that id is present in the other list to print the
value somewhere else.
However, I have the comparison code down… I think.

My problem is the silly split on the $_ as it goes through the while
loop…

Hope this makes sense.

Keep in mind
The machine I am doing this on is not online, and it is a windows
machine. So I am using Activeperl with only the modules that come with
it.

Help..



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About