IIRC the PBP advises to omit parens when unambiguously calling built-ins, because (and I agree) it removes extra-noise and improves readability. Thus, CL#1 is written as it was and it runs OK.
Then, looking at CL#2, I thought to omit a pair of parens -- see CL#3. I don't see anything becoming ambiguous, but Perl is confused -- see CL#4. And why the uniq imposes numeric context?
Also curious, if I'm explicitly imposing numeric context on sort (CL#5), Perl warns me 6 times, and not 5, as with CL#3.
>perl -lwe "sub x{@_} print sort x( qw( q w e r t y ))"
eqrtwy
>perl -MList::Util=uniq -lwe "print sort( uniq( qw( q w e r t y )))"
eqrtwy
>perl -MList::Util=uniq -lwe "print sort uniq( qw( q w e r t y ))"
Argument "w" isn't numeric in sort at -e line 1.
Argument "r" isn't numeric in sort at -e line 1.
Argument "y" isn't numeric in sort at -e line 1.
Argument "e" isn't numeric in sort at -e line 1.
Argument "t" isn't numeric in sort at -e line 1.
qwerty
>perl -MO=Deparse -MList::Util=uniq -lwe "print sort uniq( qw( q w e r
+ t y ))"
BEGIN { $^W = 1; }
BEGIN { $/ = "\n"; $\ = "\n"; }
use List::Util (split(/,/, 'uniq', 0));
print((sort uniq 'q', 'w', 'e', 'r', 't', 'y'));
-e syntax OK
>perl -lwe "print sort {$a <=> $b} qw( q w e r t y )"
Argument "q" isn't numeric in sort at -e line 1.
Argument "w" isn't numeric in sort at -e line 1.
Argument "e" isn't numeric in sort at -e line 1.
Argument "r" isn't numeric in sort at -e line 1.
Argument "t" isn't numeric in sort at -e line 1.
Argument "y" isn't numeric in sort at -e line 1.
qwerty
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.