Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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

by clintp (Curate)
on Feb 28, 2002 at 12:54 UTC ( #148200=note: print w/replies, xml ) Need Help??

in reply to 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?

And just to give you a hard time about it:

Why would I look under either when trying to understand the strange behaviour of $a or $b?

There's nothing wrong with $a and $b. You can declare them with my, with local. They hold all kinds of scalar values and references. They're nice variables, get off their backs. :)

It's not like $| (ever try putting a reference in there?), or $_ (stomp stomp stomp stomp) or even $1 (Hey! It's readonly!) .

There's something wrong with sort. It uses these perfectly nice variables in strange and perverse ways so it's worth mentioning with sort -- let's mention it there. And there's something wrong with strict because it intentionally exempts $a and $b from stricture so that sort can get away with its perversity -- we should mention it there too.

But otherwise it's not the fault of the variables. Quit blaming the variables! :)

But if you want a footnote in perlvar I'm sure no-one would reject your patch, though.

Replies are listed 'Best First'.
Re: Re: Re: Re: (re:x5 use strict....)$a and $b should be in perlvar
by demerphq (Chancellor) on Feb 28, 2002 at 13:45 UTC
    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

      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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://148200]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2018-03-17 18:48 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (225 votes). Check out past polls.