Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^2: helping along $_

by Aristotle (Chancellor)
on Sep 09, 2002 at 12:20 UTC ( #196230=note: print w/replies, xml ) Need Help??

in reply to Re: helping along $_
in thread helping along $_

Not sure I like this idea. Modules tend to end with 1; and 0 and 1 occasionally appear in void context in legit uses like 1 while s/foo/bar/;
I would rather see the simple = usable this way as in =10;
Though now that I think about it, this may be confusing to distinguish from POD directives.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^2: helping along $_
by belg4mit (Prior) on Sep 09, 2002 at 13:45 UTC
    changing 1; to $_=1; in a module is not going to do anything significant, unless $_ is not scoped to the module and something else using the module expects $_ to be undefined initially. Your other example is not a useless use of constant in void context, I'm not sure it's even in void context, but I'll take your word for that. It's not useless because it's part of a larger, more meaningful statement, if the remainder of the line consisted of only numeric operations, numbers, (variables) and semi-colon, that would be useless use... and safe to muck with.

    perl -pew "s/\b;([mnst])/'$1/g"

      Actually, 0 and 1 are special-cased in perl to not throw a warning. Consider:
      $ perl -w -e'1;' -e'10;' Useless use of a constant in void context at -e line 2

      Makeshifts last the longest.

        Yes, okay. But that doesn't really affect how this hypothetical behavior for ARGHelper would be, does it? It simply means that defining what constitutes assignment with the same parameters as what incurs the warning is slightly too restrictive (as it leaves out 0 and 1), but the idea is still there and otherwise valid. I don't think you've made your case as to how this could negatively affect things; I already pointed out the bit about scope. An assignment returns its value, so the statement still evaluates to 0 or 1, whether or not an assignment is taking place.
        % echo '$_=0;' >! /tmp/ ; perl -Mlib=/tmp -Ma did not return a true value. BEGIN failed--compilation aborted.

        perl -pew "s/\b;([mnst])/'$1/g"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://196230]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2019-05-20 09:18 GMT
Find Nodes?
    Voting Booth?
    Do you enjoy 3D movies?

    Results (125 votes). Check out past polls.