Re: inverting List::Compare

2009-01-14 Thread Dr.Ruud
Dr.Ruud wrote: John W. Krahn: my @llist = do { open my $fh, '<', $lfile or die "Unable to open '$lfile': $!"; <$fh>; }; Again, especially for biggish files, this is a better way: my @llist; { open my $fh, '<', $lfile or die "'$lfile': $!"; @llist = <$fh>; } Rand

Re: inverting List::Compare

2009-01-13 Thread Dr.Ruud
John W. Krahn wrote: my @llist = do { open my $fh, '<', $lfile or die "Unable to open '$lfile': $!"; <$fh>; }; Again, especially for biggish files, this is a better way: my @llist; { open my $fh, '<', $lfile or die "'$lfile': $!"; @llist = <$fh>; } Randall's idea

Re: inverting List::Compare

2009-01-12 Thread John Refior
On Sun, Jan 4, 2009 at 7:42 PM, John W. Krahn wrote: >>> You should include the $! variable in the die string so that you know why >>> the >>> open failed. I suggest >>> >>> my @llist; >>> { >>>open my $fh, '<', $lfile or die "Unable to open '$lfile': $!"; >>>@llist = <$fh>; >>> } >> >>

Re: inverting List::Compare

2009-01-04 Thread John W. Krahn
John Refior wrote: Rob Dixon wrote: David Newman wrote: # get files open(DAT, $lfile) or die("unable to open"); my @Llist = ; close(DAT); You should include the $! variable in the die string so that you know why the open failed. I suggest my @llist; { open my $fh, '<', $lfile or d

Re: Was re: inverting List::Compare

2009-01-04 Thread Jay Savage
On Sun, Jan 4, 2009 at 11:45 AM, Bob goolsby wrote: > Not 'wrong headed', just a compiler compiler optimization. By putting > the declarations before the usage, you reduced the number of complete > passes through the source by one and made the parsing code easier. > This is an artifact from the t

Re: inverting List::Compare

2009-01-04 Thread John Refior
>> # get files >> open(DAT, $lfile) or die("unable to open"); >> >> my @Llist = ; >> >> close(DAT); > > You should include the $! variable in the die string so that you know why the > open failed. I suggest > > my @llist; > { >open my $fh, '<', $lfile or die "Unable to open '$lfile': $!"; >

Re: Was re: inverting List::Compare

2009-01-04 Thread Bob goolsby
Not 'wrong headed', just a compiler compiler optimization. By putting the declarations before the usage, you reduced the number of complete passes through the source by one and made the parsing code easier. This is an artifact from the time when Machine-Time was expensive and Programmer-Time was (

Was re: inverting List::Compare

2009-01-04 Thread Telemachus
On Sat Jan 03 2009 @ 11:00, John W. Krahn wrote: >>> David Newman wrote: >> I always found it "cleaner", and have heard others say it's preferable, >> to declare all variables at the top of the program (although admittedly >> I didn't do that even in this short script). > > It is always better to l

Re: inverting List::Compare

2009-01-03 Thread John W. Krahn
David Newman wrote: On 1/2/09 5:22 PM, Rob Dixon wrote: David Newman wrote: my $lfile = $ARGV[0]; my $rfile = $ARGV[1]; It would also be nice to make sure that there are in fact two parameters die "The parameters must be the the two files for comparison" unless @ARGV == 2; my

Re: inverting List::Compare

2009-01-03 Thread Telemachus
On Sat Jan 03 2009 @ 9:21, David Newman wrote: > On 1/2/09 5:22 PM, Rob Dixon wrote: > >> #!/usr/bin/perl -w > >> > >> use strict; > > > > You should also use the warnings pragma instead of the command-line switch. > > > > use warnings; > > OK. Why is this better? My understanding is that th

Re: inverting List::Compare

2009-01-03 Thread David Newman
On 1/2/09 5:22 PM, Rob Dixon wrote: > David Newman wrote: >> Greetings. I have a working script (pasted below) that uses >> List::Compare to find common lines in two files. >> >> Now I am again looking to compare two files but this time exclude any >> lines in file 1 that appear in file 2. I don't

Re: inverting List::Compare

2009-01-03 Thread John W. Krahn
Rob Dixon wrote: David Newman wrote: foreach my $union (@union) { print "$union"; } You shouldn't put $union in quotes, and the loop is better written as print for @union; print @union; Should work just as well. John -- Those people who think they know everything are a grea

Re: inverting List::Compare

2009-01-02 Thread Rob Dixon
David Newman wrote: > > Greetings. I have a working script (pasted below) that uses > List::Compare to find common lines in two files. > > Now I am again looking to compare two files but this time exclude any > lines in file 1 that appear in file 2. I don't see anything in the > List::Compare docu

inverting List::Compare

2009-01-02 Thread David Newman
Greetings. I have a working script (pasted below) that uses List::Compare to find common lines in two files. Now I am again looking to compare two files but this time exclude any lines in file 1 that appear in file 2. I don't see anything in the List::Compare documentation on how to do this. Than