develooper Front page | perl.beginners | Postings from March 2002

RE: Can I do this with perl?

Thread Previous | Thread Next
From:
Nikola Janceski
Date:
March 4, 2002 07:20
Subject:
RE: Can I do this with perl?
Message ID:
1449413DA482D311B67000508B5A12F50592DE07@nyexchange01.summithq.com
Yes you can do it with perl, and I suggest using hashes.

open(FILE, "$file");
my %seen;
while(<FILE>){
	my ($item9, $item10) = (split /\|/, $_)[8,9];
	if(exists $seen{$item9}){
		if($itme10 > $seen{$item9}){
			# the new $item10 is larger than the last one seen
			} else {
			# the contrary is true
			}
		
		} else {
		$seen{$item9} = $itme10;
		}
close FILE;

-----Original Message-----
From: Dave Adams [mailto:d.adams@uts.an]
Sent: Monday, March 04, 2002 10:10 AM
To: beginners@perl.org
Subject: Can I do this with perl?


Hi there,

I have a problem which I would like to use perl to resolve, however I'm not
sure if it is possible to do. 

I need to scan a file and check some conditions, first if field 9 is
duplicated on 1 or more rows, then I need to check field 10 to see which is
the greater value and then only print the whole row where field 10 is the
greater, if field 9 is not a duplicate then print the whole row.
An example of the data is below.

28525|U2|4CY0|50|6775.15|2002-02-07|10461|321.43|102040724|102040773|
28526|U2|4CY0|25|3571.78|2002-02-07|6107|167.74|102040774|102040798|
28527|U2|4CY0|50|6930.3|2002-02-07|11376|324.12|102040774|102040823|
28528|U2|4CY0|25|4640.28|2002-02-07|4800|217.43|102040824|102040848|
28529|U2|4CY0|50|8432.05|2002-02-07|9023|392.03|102040824|102040873|

Dave

----------------------------------------------------------------------------
--------------------
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.


Thread Previous | 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