[Chicago-talk] get array element from a function return

Elliot Shank chicago.pm at galumph.com
Fri Dec 3 16:39:30 PST 2010

On 12/3/10 2:13 PM, tiger peng wrote:
> Thanks,
> What's wrong with command below?
> :) ls -l | perl -nle 'print (split)[0]'
> syntax error at -e line 1, near ")["
> Execution of -e aborted due to compilation errors.

It's because print is being interpreted as a function, i.e. you're attempting to put a subscript after "print (split)".  If the first significant thing after "print" or "say" is an opening parenthesis, then the function grabs that before anything else in the statement.  For example,

     say ("blah"), "lah";

will only emit "blah" even though

     say "blah", ("lah")

will emit "blahlah".

More information about the Chicago-talk mailing list