Thanks for the question, Ed. I agree, this "construction" doesn't look
nice. I'm not a Perl guru and I just did what I need to be done - using
simple logic and Perl's functions I know (or rather I think I know). Here
is my explanation:
1. I don't want the line to be printed if its element exists in the second
list so I need $comp = $aref->[4] cmp $bref->[0
2. I want "good" line to be printed once
3.last NOSTOCK if $comp eq 0 # it exits the inner loop
4.next NOSTOCK if $comp ne 0 # it starts the inner loop with the next
element from my second list
5. print if $comp ne 0 # it prints the line from the first file when its
element is not equal the element from the second list. But what if the
other element of the second list is equal (vice versa, actually)? I'd have
one line printed as many times as $comp ne 0 is true. And that's not what I
wanted - the line printed once only if its element is not in the second list.
Take a look at the solution posted by Douglas Wilson. Isn't it beautiful?
Thanks again, Douglas. You, and guys like you, are helping people to
discover the beauty and the power of Perl. I hope I'll be able to help
somebody in the future.
Greg
At 04:32 PM 4/26/2000, you wrote:
>I'm new to Perl, but it looks to me as if the line -- next NOSTOCK if $comp
>ne 0; -- is redundant. Wouldn't the loop behave the same without that
>line?
> Ed Ewen
> (404) 575-3531
>[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>
>
> -----Original Message-----
> From: Greg Wardawy [SMTP:[EMAIL PROTECTED]]
> Sent: Wednesday, April 26, 2000 5:24 PM
> To: Perl-Win32-Users Mailing List
> Subject: Re: Extracting lines
>
> Thanks Douglas,
> I'm reposting plain text:
> To: "Perl-Win32-Users Mailing List"
> <[EMAIL PROTECTED]> Subject: Extracting
>lines
> Hello all,
> I need to print just the lines where the fourth element is not a
>member of
> the second list so I wrote the following code:
> ####################
> #!perl -w
> open(NOSTOCK, "< nostock.csv") || die "can't open nostock.csv for
>reading:
> $_!";
> open(ORD, "< custord2") || die "can't open custord2 for reading:
>$_!";
> open(CUST, "> cust") || die "can't create cust: $_!";
> my ($line, @ord, $i, $aref, @nostock, $bref, $n, $j);
> while ($line = <NOSTOCK>) {
> push @nostock, [ split ',', $line ];
> }
> while ($line = <ORD>) {
> push @ord, [ split ',', $line ];
> }
> ORD: for $i ( 0 .. $#ord ) {
> $aref = $ord[$i];
> $n = @$aref - 1;
> NOSTOCK: for $j ( 0 .. $#nostock) {
> $bref = $nostock[$j];
> $n = @$bref - 1;
> $comp = $aref->[4] cmp $bref->[0];
> last NOSTOCK if $comp eq 0;
> next NOSTOCK if $comp ne 0;
> }
> print
>
>"$aref->[0],$aref->[1],$aref->[2],$aref->[3],$aref->[4],$aref->[5],$aref->[6
>],$aref->[7],$aref->[8],$aref->[9]"
> if $comp ne 0;
> }
> close(NOSTOCK);
> close(ORD);
> close(CUST);
> ######################
>
> In what other ways (more efficient, faster or just different) can I
> complete this task?
>
> Here are parts of my input files:
> # custord2:
> 3,1000000005,R496055,348,PENFUZZY,11.99,1,04,25,00
> 3,1000000005,R496055,348,RDPILOT,7.99,1,04,25,00
> 3,1000000005,R496055,351,HOUWHERE,4.95,1,04,25,00
> 3,1000000005,R496055,351,PENDINNER,6.95,1,04,25,00
> 3,1000000005,R496055,351,RANONEFISH,8.95,1,04,25,00
> 3,1000000005,R496055,351,SIMCHEERIOS,5.99,1,04,25,00
> 3,1000000005,R496055,359,RANGREEN,8.95,1,04,25,00
> # nostock.csv:
> FNWDISPLAY,
> HAVCASTLE,
> HAVCONSTRUCTION,
> HAVEASYFAMILY,
> HAVMASTERCKDLX,
> MERNEWBAKING,
> MORHORSD,
> RANGREEN,
> RANONEFISH,
> STRSMALL,
> TLCELMOART,
> TLCLITTLEBEAR,
> TLCMADELINE,
> WARLITTLEMEALS,
>
> Thanks in advance.
> Greg
>
>
>
>
> ---
> You are currently subscribed to perl-win32-users as:
>[EMAIL PROTECTED]
> To unsubscribe, forward this message to
> [EMAIL PROTECTED]
> For non-automated Mailing List support, send email to
> [EMAIL PROTECTED]
>
>---
>You are currently subscribed to perl-win32-users as: [EMAIL PROTECTED]
>To unsubscribe, forward this message to
> [EMAIL PROTECTED]
>For non-automated Mailing List support, send email to
> [EMAIL PROTECTED]
---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
[EMAIL PROTECTED]
For non-automated Mailing List support, send email to
[EMAIL PROTECTED]