print (...) interpreted as function at C:\test.pl line 11.
syntax error at C:\test.pl line 11, near ")["
From perldiag:
%s (...) interpreted as function
(W syntax) You've run afoul of the rule that says that any list operator followed by parentheses turns into a function, with all the list operators arguments found inside the parentheses. See Terms and List Operators (Leftward) in the perlop manpage.
I'm not a guru on these things, but I think the parens you used to place the regex in list context (and take the slice) are interpreted by perl to be the optional parens around the arguments to the print function. You need an extra set to make everything happy:
print( ('abcd' =~ /(\w)\w(\w)/ )[0] ); # prints 'a'
Update: Yup, that was it. Added diagnostic message from perldiag.
|