jwkrahn already gave the right answer, but I suspect you might not understand it.

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:

push @foo, $this, $that;
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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.