so foreach dumps the entire file into memory before iterating over the lines. Good to know. Thanks.
I don't think your solution will work. Since the count being taken is going to be sparadic. somelements only = 1 at the BOF but by EOF it equals 4. Since you tested per line your results will be bad because at test time for that line somelement only = 1 when actually it was equal to 4. Wow that confused me :) > -----Original Message----- > From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]] > Sent: Thursday, January 02, 2003 10:30 AM > To: Paul Kraus > Cc: 'Perl' > Subject: RE: Restarting at top of file > > > On Jan 2, Paul Kraus said: > > >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. > > Watch me. :) > > >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? > > foreach (<FOO>) reads ALL the lines of <FOO> at once, and > makes a big list. while (<FOO>) only reads one line at a time. > > >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); > >} > > while (<PEL>) { > chomp; > s/ +//g; > my ($value, $field) = split /,/; > $dup{$field}++; > if ($dup{field} == 1) { $vend{$field} = $value } > else { delete $vend{$field} } > } > > That looks to me like it will work. > > -- > 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]