in reply to Re: why does push not default to $_?
in thread why does push not default to $_?

> Moreover, push mutates its first operand and it would really be a bad idea to change data and at the same time hide from the developer how the data is being changed.

Well for me, calling push with only one parameter is quite obvious. At least not less than print without parameter.

Please, in which chapter did you find that quote in the camel book?

Cheers Rolf

UPDATE: here what I found in 2.9.3 Global Special Variables
Here are the places where Perl will assume $_ even if you don't use it:

    *      Various unary functions, including functions like ord and int, 
 as well as all the file tests (-f, -d) except for -t, which defaults to STDIN.
    *      Various list functions like print and unlink.
    *      The pattern-matching operations m//, s///, and tr/// when used 
 without an =~ operator.
    *      The default iterator variable in a foreach loop if no other variable
 is supplied.
    *      The implicit iterator variable in the grep and map functions.
    *      The default place to put an input record when a <FH> operation's
 result is tested by itself as the sole criterion of a while test. Note that
 outside of a while test, this will not happen. 

Mnemonic: underline is the underlying operand in certain operations.

Well various doesn't sound very specific, and print and unlink are not unary.

Replies are listed 'Best First'.
Re^3: why does push not default to $_?
by ptoulis (Scribe) on Dec 06, 2008 at 01:53 UTC
    Well for me, calling push with only one parameter is quite obvious. At least not less than print without parameter.
    The difference is that print does not alter its operands but push does. Even ignoring these there is hardly a good reason to use $_ for push. For example, in iterators which set the $_ you might want to use something like: for(1..100) { push @a;}, but still you would be better going by push @a,(1..100);
    Please, in which chapter did you find that quote in the camel book?
    You can find the quote in Chapter 28-Special Names, page 659.
      which copy? I already updated in the previous post what I found in "Second Edition, September 1996.

      Please compare, in my copy, there is no mention about different handling of functions denpending on if they alter operands.

      Cheers Rolf