Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: list slice

by bart (Canon)
on Jul 21, 2006 at 18:25 UTC ( #562912=note: print w/ replies, xml ) Need Help??


in reply to list slice

You were so close. This works:

my $year = (localtime((stat($file))[9]))[5] + 1900;

The basic idea is that to take an indexed item from the result of a function that returns a list, is to wrap the function call in extra parens. Like this:

my $sixth = (foo(@args))[5];

Alternatively, you can wrap it in an anonymous array, too:

my $sixth = [foo(@args)]->[5];
The arrow is not optional.

So, this will work, too:

my $year = [localtime([stat($file)]->[9])]->[5] + 1900;


Comment on Re: list slice
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://562912]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (15)
As of 2015-07-02 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (44 votes), past polls