Possibly useful perl script to filter lines in one file out of another.

B

Ben Burch

Why did I know somebody was going to object if I didn't make my hack
into a textbook example?

Tad J said:
use warnings;
use strict;


You should always, yes *always*, check the return value from open():

open my $EXCLUDE, '<', $file2 or die "could not open '$file2' $!";

Nope. Perl programmers are fond of their one-liners, but they are
unclear and missed in peer code inspections.

Much better is;

my $status = open (EXCLUDE, '<', $file2);

if( !$status )
{
print "File open error $!";
exit 1;
}

(You can die() if you want to, but no reason to do it unless you plan
to handle the signal...)

And there is no reason to make the FHs in scalar form at all, and its
less clear when you do.
unless ( exists $exclude{$line} )

Unless is an abomination when it comes to code that will have faults
found in code review.
or at least make wise use of whitespace and punctuation:

if ( ! exists $exclude{$line} )

Sure, run it through tidy and get some white space if you like, I never
have any trouble reading it without.
 
U

Uri Guttman

BB> Why did I know somebody was going to object if I didn't make my hack
BB> into a textbook example?

because code posted here is always up for review.


BB> Nope. Perl programmers are fond of their one-liners, but they are
BB> unclear and missed in peer code inspections.

huh? open or die is such a common idiom it is not missed. how much code
review do you do?

BB> Much better is;

BB> my $status = open (EXCLUDE, '<', $file2);

BB> if( !$status )
BB> {
BB> print "File open error $!";
BB> exit 1;
BB> }

and print/exit is what die does. that is 6 lines of verbosity vs 1 clear
line.

BB> (You can die() if you want to, but no reason to do it unless you plan
BB> to handle the signal...)

what???

BB> And there is no reason to make the FHs in scalar form at all, and its
BB> less clear when you do.

huh?? lexical handles are not globals which is the point of
them. globals are bad. if you try to defend globals, you are not on
solid ground.

BB> Unless is an abomination when it comes to code that will have faults
BB> found in code review.

again, who is reviewing that code? kindergarten coders? unless is
perfectly fine and is better than an extra noisy negation when reading code.

BB> Sure, run it through tidy and get some white space if you like, I never
BB> have any trouble reading it without.

but that won't pass code review!!

goose, meet gander!

uri
 
N

Nathan Keel

Ben said:
my $status = open (EXCLUDE, '<', $file2);

if( !$status )
{
print "File open error $!";
exit 1;
}

I don't get the correlation of one liners and Perl programmers? Some do
often when they can or want, and some do not. I wasn't aware one was
more frequent than the other? Anyway, what do you think you're if
statement is checking the status of? The return value of open is what.
No one said you have to (or should) die.
 
E

Eric Pozharski

*SKIP*
BB> my $status = open (EXCLUDE, '<', $file2);

BB> if( !$status )
BB> {
BB> print "File open error $!";
BB> exit 1;
BB> }

and print/exit is what die does. that is 6 lines of verbosity vs 1 clear
line.

And if code dies in debugger then debugger dumps stack. What's not the
case B<print>-B<exit>.

*CUT*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top