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:
The arrow is not optional.my $sixth = [foo(@args)]->[5];
So, this will work, too:
my $year = [localtime([stat($file)]->[9])]->[5] + 1900;
|
---|
In Section
Seekers of Perl Wisdom