in reply to Re: Should We Have A "Red Flags" Area?
in thread Should We Have A "Red Flags" Area?

Couldn't agree more. I'm not too familiar with Perl internals and perldelta but couldn't differences between implementations and releases also cause problems? For example what might be a bad practice in perl 5.8 on wintel might be the best way for perl 4 on solaris?

Also, as for strict vars, why isn't this the specified behaviour for all perl programs? It's scoped that way in many other languages, why is Perl different? It seems to just be inviting trouble.

  • Comment on Re: Re: Should We Have A "Red Flags" Area?

Replies are listed 'Best First'.
Re: Re: Re: Should We Have A "Red Flags" Area?
by chromatic (Archbishop) on Feb 17, 2003 at 03:59 UTC

    Perl is different so you can write useful programs as one-liners.

      Placing my supreme opposition to obfuscation and other unecessarily dense code aside (every script should be clearly written and placed in a nice, well named little file with good documentation), why would you need a complete lack of proper scoping to create useful one liners? Could you provide a few examples? Thanks.

        Hm, I think I'm doomed to fail with that parenthetical remark. Still, compare this program:

        perl -pe -i.bak 's/PERL/Perl/g' *.txt

        with this one:

        perl -e 'use File::Copy;  foreach my $file (@args) { open my $fh, $file or die "Cannot open $file: $!\n";  my @lines; copy( $file, $file . ".bak"; while (defined( my $line = <$fh> )) { $line =~ s/PERL/Perl/;  push @lines, $line; } close $fh;  open $fh, '>', $file or die "Cannot write to $file: $!\n"; print $fh, @lines; }'

        The first uses global variables. The second uses lexicals. I typed both straight off the top of my head, just as I would at a command line. I'm willing to bet that the first doesn't have any errors. I'll be pleasantly surprised if the second doesn't have at least one typo.

        Update: Five days later, someone does spot a typo! Well done, coolmichael! (completely unintentional on my part)