in reply to Question about list context

It's not a issue of context, but rather of an ambiguous syntax; perl is just making the wrong guess as to what you mean. In your first example, Perl thinks that the parens should be interepreted as a function call, like print("foo"). To help perl out, disambiguate the expression with +, like this:

print +(split "\t", $line)[0], "\n" ;

Update:I posted another example of a similar phenomenon in this recent node.

the lowliest monk

Replies are listed 'Best First'.
Re^2: Question about list context
by rir (Vicar) on Apr 14, 2005 at 16:17 UTC
    This is not considered ambiguous so far as Perl is concerned. If you have warnings enabled Perl will warn you that it is running ambiguous code. In the case of function_name ( something_or_nothing ) there is no ambiguity, there is the clear rule that if it looks like a function, it is a function.

    In the case of print ( something ), more; you will be told print (...) interpreted as function not because it is ambiguous but because it is usually unintended that more dangle after a comma after a print function.

    Be well
    rir

    Updated: corrected spelling unintented