Here's a list of perl builtins that default to act on $_ when given no argument.

There are other operations that use $_ implicitly. For example, regexps, substitutions, and transliterations (m, s, tr, y) act on $_ unless a different string is given by the =~ operator; map, grep, the for statement modifier, and for loops without explicit loop variable specified use $_ as the loop variable; a diamond operator in a while loop stores the line to $_.

Below are some functions that do not default to $_.

Note that a few functions behave differently if they are called with an empty pair of parenthesis (usually taken as an empty list).

The following functions accept a filehandle, directory handle, label, or bareword as an argument, and thus don't default to $_. (I do not list those functions that need an array or hash argument, like pop.)

I've compiled these lists using both the perldoc perlfunc and testing how the functions actually behave with perl (5.8.8 i686-linux). For this reason, there can be errors and omissions in this list. If you know about any omission, please contact me.

Update: added readmore.

Update 2012-12-27: added the new evalbytes function.

Update 2014-01-29: added changes to mkdir and unpack.


In reply to Builtin functions defaulting to $_ by ambrus

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.