open(FILE, "yourfile") or die "can't open $!"; my(%LINES); while(<FILE>){ my($key) = split; $LINES{$key) = $_ unless exists $LINES{$key); } close FILE;
# %LINES now has key value pairs of '123' and '444' as the keys and the value is the first occurence in the file. > -----Original Message----- > From: Paul and Joann Van Dalen [mailto:[EMAIL PROTECTED]] > Sent: Monday, September 30, 2002 9:36 PM > To: [EMAIL PROTECTED] > Subject: Creating hash? > > > Hi all, > > Given an input file that has the following records: > > 123 ABC XX112 YYYY Zzzzzzzzzz > 123 DEF XX113 WWWW Zzzzzzzzz > 123 EEF XX112 YYYY Zzzzzzzzzz > 444 ccc vvbfd QQQQ ccccccccc > 444 CCd vvbfd QQQQ ccccccccc > 444 ddd ssddd QQQQ xxxxxxxx > > I need to focus on the first column (the input file is > already sorted on > that field) and, grouped by the first column, pull out > the first record of that group. > e.g., I would need to have the following from the above as output: > > 123 ABC XX112 YYYY Zzzzzzzzzz > 444 ccc vvbfd QQQQ ccccccccc > > I believe I'd need something like a hash, where for every > record within > a group defined by the common value of the first column, I take the > numerically first occurance of that group, but I don't know how to do > that in Perl. Would it take a loop for each group within the loop for > the entire file?? > > Thanks very much, > Paul > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > ---------------------------------------------------------------------------- -------------------- The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]