local($/ = chr 4) works fine. "\x04" is assigned to $/, $/ is returned by the assignment, then $/ is localized.

(local $/) = chr 4; would be the proper parenthesisation if you want the localisation to occur first.

the parenthesis following a function are optional, but in some cases, they seem to be downright forbidden.

local($/) = chr 4; would also be valid, but it has different semantics than local $/ = chr 4;

local ($s) is considered a list when found on the LHS of an assignment, causing the list assignment (aassign) to be used. local $s is considered to be a scalar, so a scalar assignment (sassign) would be used then.

$ perl -MO=Concise,-exec -e'local $s = "foo"' 2>&1 | grep assign 5 <2> sassign vKS/2 $ perl -MO=Concise,-exec -e'local ($s) = "foo"' 2>&1 | grep assign 7 <2> aassign[t2] vKS

In practice:

$ perl -le'my $x = local $s = "foo"; print $x' foo $ perl -le'my $x = local ($s) = "foo"; print $x' 1

my, eof and use also vary in semantics based on the presence of parens.

There is another area where I've noticed that parenthesis seem to be forbidden

Red herring. It has nothing to do with parenthesis. map has two calling conventions, both of which work with and without parens:

Your map has a block *and* a comma, which is wrong.

map( { print $_."\n" } @list ); # Block and no comma works. map( print($_."\n"), @list ); # Expression with comma works. map { print $_."\n" } @list; # Block and no comma works. map print($_."\n"), @list; # Expression with comma works.

By the way, why are you using map in void context?

print "$_\n" for @list;

In reply to Re: Why is local($/) different from local $/? by ikegami
in thread Why is local($/) different from local $/? by pileofrogs

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.