Your question is yet another example where using strict and warnings makes things a whole lot easier to understand:
print ("a", "b")[1]; print qw(a, b)[1]; __END__ # Result: syntax error at x.pl line 3, near ")[" Execution of x.pl aborted due to compilation errors.

But when you add those 2 magic lines at the top:

use strict; use warnings; print ("a", "b")[1]; print qw(a, b)[1]; __END__ print (...) interpreted as function at x.pl line 5. Possible attempt to separate words with commas at x.pl line 6. syntax error at prog.pl line 5, near ")[" Execution of x.pl aborted due to compilation errors.

That line about "print (...) interpreted as function ..." is what others (eg. mreece and jdporter) have already discussed.

Another way of looking at it is that:

print ("a", "b")[1];

is the same, precedence-wise, as:

(print ("a", "b"))[1];

which doesn't make sense (ie. is a syntax error).  You have to force the desired precedence with:

print (("a", "b")[1]);

The line "Possible attempt to separate words with commas" is just alerting you to the fact that instead of:

print qw(a, b)[1];

you probably actually meant something more like:

print qw(a b)[1];

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re^4: print question by liverpole
in thread print question by Anonymous Monk

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.