http://www.perlmonks.org?node_id=196091


in reply to helping along $_

Hmm, interesting. Not sure how useful that really is, but here are some ideas to extend it.
  1. useless use of constant in void context becomes assignment. So...
    10; #is equivalent to $_=10;
  2. Add support for some of the perl6 operators such as //=
  3. UPDATE: An example script using this, which is an interactive calculator.
    > 22/7; < 3.14285714285714 > *=9**2; < 254.571428571429

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

Replies are listed 'Best First'.
Re^2: helping along $_
by Aristotle (Chancellor) on Sep 09, 2002 at 12:20 UTC
    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.

      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.