That was partial code. Here is the completed script. At least the pertinent portion.
As you can see I am building a hash on the first pass. Then on the second pass I am building a second hash but I am checking the first hash to see if it had a count greater then two. I don't see any other way to do this except two passes through the file. Correct me if I am wrong. I am using a foreach loop because I just picked it. :) it situations like this I never really saw a difference between while and foreach. Why would I want to use a while loop instead? #add duplicates to hash foreach (<PEL>){ chomp; @temp=split /,/,$_; $_=~s/ //g foreach (@temp); $dup{$temp[1]}++; } #add item->vendor part numbers to hash if don't exist in dup hash seek PEL, 0, 0; foreach (<PEL>){ chomp; @temp=split /,/,$_; $_=~s/ //g foreach (@temp); $vend{$temp[1]}=$temp[0] unless ($dup{$temp[1]} > 1); } > -----Original Message----- > From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]] > Sent: Thursday, January 02, 2003 10:02 AM > To: Paul Kraus > Cc: Perl > Subject: Re: Restarting at top of file > > > On Jan 2, Paul Kraus said: > > >I want to read through a file and the read through it again. However > >the only way it seems to work for me is if I open the file, Read the > >file, > > WHY do you want to read the file twice? Is there some way > you can do two things at once? > > >foreach (<PEL>){ > > chomp; > > @temp=split /,/,$_; > > $_=~s/ //g foreach (@temp); > > $dup{$temp[1]}++; > >} > > > >foreach (<PEL>){ > > chomp; > > @temp=split /,/,$_; > > print "$_\n" foreach (@temp); > > $_=~s/ //g foreach (@temp); > > $vend{$temp[1]}=$temp[0]; > >} > > Why are you using a foreach loop, rather than a while loop? > And you CAN do these two things at the same time. > > while (<PEL>) { > chomp; > s/ +//g; # remove spaces > my ($value, $field) = split /,/; > $dup{$field}++; > $vend{$field} = $value; > } > > -- > Jeff "japhy" Pinyan [EMAIL PROTECTED] > http://www.pobox.com/~japhy/ > RPI Acacia brother #734 > http://www.perlmonks.org/ http://www.cpan.org/ > <stu> what does y/// stand for? <tenderpuss> why, > yansliterate of course. [ I'm looking for programming work. > If you like my work, let me know. ] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]