> 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?
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. | [reply] |
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.
| [reply] [d/l] [select] |
| [reply] |