Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

In reply to Perl parser gets confused with call to "sort" w/o parens by vr

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



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-24 01:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found