A lot of Perl built-ins, and a few user defined functions, have "prototypes". What prototypes do is change Perl's usual argument list rules. We take some of these for granted:
If you think about it, push can't be getting the normal argument list, because if it was then it would get a list of everything to go into @foo, but wouldn't know about @foo. Instead it has a prototype that gives it a reference to @foo, and then the elements to add to it.push @foo, $this, $that;
Anyways there are many different possible prototypes. You can, as with push, convert an array into a reference to an array. Or, as with each, a hash into a reference to a hash. Or you can, as sysread does, convert arguments into scalars. Which means that if you pass it an array, it will coerce the array into a scalar saying the length of the array.
So should you use them? In general, no. As you discovered, prototypes violate the principle of not surprising people. Some uses, such as push, get amortized over so many uses that people just take them for granted. But unless you're using a function that often, you don't want to use prototypes.
Unfortunately we can't ever change existing prototypes on the lesser used built-ins because there is code that depends on them. And, as with sysread, they will cause surprise from time to time.
In reply to Re: What is wrong with "sysread @list"
by tilly
in thread What is wrong with "sysread @list"
by tfoertsch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |