in reply to Re: Re: Re: (re:x5 use strict....)$a and $b should be in perlvar
in thread use strict won't require explicit name for all variables?

Well I would say they should be documented under perlvar because of one simple reason: They allow action at a distance, which can be one of the most perverse bugs to track down.

Consider a novice-perl maintainer. He has to modify an old module. He uses the vars $a and $b to effect some change. Unknown to him however some part of the code calls a subroutine that overwrites $a and $b. He gets weird results and cant explain them. He looks in perlvar but sees no mention. He doesnt even know that sort is being used so he doesnt know to look in perlfunc. He doesnt look at the strict documentation because like a good novice he has strict turned on already. How other by asking or by luck is he to know or figure out what the hell is going on? (Oh im assuming that as a novice he found using the debugger as imposing as I did at the start and doesnt use it, or doesnt know how at all.)

See what I mean?

But you're right that instead of submitting a bug report, I should submit a patch. Which I will do.

Yves / DeMerphq
--
When to use Prototypes?
Advanced Sorting - GRT - Guttman Rosler Transform

  • Comment on Re: Re: Re: Re: (re:x5 use strict....)$a and $b should be in perlvar

Replies are listed 'Best First'.
Mistaken notions of $a/$b strict
by clintp (Curate) on Feb 28, 2002 at 15:43 UTC
    My answer was tongue firmly in cheek. Note the tone and the :)'s scattered about. But please, submit a patch.

    To clear up a misconception though, your "action at a distance" horror scenario there won't happen. No sir. $a and $b are (apparently) local'd to the block:

    @list=qw( one two three four five ); $a="Hello"; $b="World"; sort { $a <=> $b } @list; print "$a $b"; # Hello World
    I knew this. Several others in channel this morning knew this. But in an ironic twist of events, I can't find where that localization is documented. I think I see it in the Perl source...but not in the docs.
      Ah, but the "action at a distance" most certainly does occur. If you create a sorting sub in one module and use it in another ... Look at the following code:
      my $a = 5; my @b = reverse (0 .. 9); print "@b\n"; sub boo { $a <=> $b } @b = sort boo @b; print "@b\n"; print $a,$/; ---- 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 9 8 5 6 7 5
      Note the lack of sorting after 4. :-)

      ------
      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

        While I don't have time to fully explain it, you can actually use prototypes(bleck) to avoid the weirdness in $a and $b (ughhh) for 5.6 and above....
        sub boo ($$) { my ($a,$b) = @_; $a <=> $b }

        -Blake