From: "Siegfried Heintze" <[EMAIL PROTECTED]>
> This works and does what I want it to:
> 
> perl -e '@x = split("\\.", "a.b.c"); print $x[0];'
> 
> Why does not this work?
> perl -e 'print  @{split("\\.", "a.b.c")}[0];'
> 
> Is there a compact way to take a slice of a split (or other function
> that returns an array) without creating a temporary variable?

perl -e 'print ((split("\\.", "a.b.c"))[0]);'

It's a bit tricky. The outermost braces belong to print(), the next 
ones enclose the call to split() so that it can be sliced and the 
innermost enclose the parameters for split(). Only the innermost may 
be left out.

This makes the slicing of function result a bit clearer I think:

        ($hour, $minute, $sec) = (localtime())[2,1,0];

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to