in reply to Re^2: a simple exercise in readability
in thread a simple exercise in readability

You have changed liverpole's

# Command-line (my $x = shift) or die $syntax; (my $y = shift) or die $syntax; # Validity checking ($x =~ /^-?\d+$/) or die "$iam: value $x not an integer\n"; ($y =~ /^-?\d+$/) or die "$iam: value $y not an integer\n";

to

my $start = shift @ARGV; my $end = shift @ARGV;

It seems to me that you have gained more meaningful variable names but you have lost two forms of error checking, making your script less robust. You no longer detect if the user fails to supply enough arguments and you fail to validate those arguments that are supplied. Probably a backward step.

Cheers,

JohnGG

Update: As apotheon pointed out, I completely missed an element of his code. Please ignore this post.

Replies are listed 'Best First'.
Re^4: a simple exercise in readability
by apotheon (Deacon) on Jan 15, 2007 at 14:55 UTC

    You appear to have missed the significance of the following in my version:

    HELP_MESSAGE() and exit unless $ARGV[1]; foreach (@ARGV) { HELP_MESSAGE() and exit unless /^-?\d+$/ }

    As I stated, I removed the error checking from the variable assignments et cetera. The reason I did so is for maintainability. If you didn't miss that, and find that my approach is deficient, please let me know how it fails to achieve roughly the same results in use.

    edit: More explicitly, I've changed liverpole's

    use File::Basename; # [unrelated code] my $iam = basename $0; # [unrelated code] # Command-line (my $x = shift) or die $syntax; (my $y = shift) or die $syntax; # Validity checking ($x =~ /^-?\d+$/) or die "$iam: value $x not an integer\n"; ($y =~ /^-?\d+$/) or die "$iam: value $y not an integer\n";

    to . . .

    HELP_MESSAGE() and exit unless $ARGV[1]; foreach (@ARGV) { HELP_MESSAGE() and exit unless /^-?\d+$/ } my $start = shift @ARGV; my $end = shift @ARGV;

    edit: johngg pointed out the "unless" bug above, where unless @ARGV should read unless defined @ARGV instead.

    print substr("Just another Perl hacker", 0, -2);
    - apotheon
    CopyWrite Chad Perrin

      Sorry, I did miss that. I shouldn't post after two nights of hardly any sleep :(

      Cheers,

      JohnGG