eXile has asked for the wisdom of the Perl Monks concerning the following question:
I'd like to know the year (in localtime) a file was last modified.
I know I can do that with:
I was wondering if there was a readable shorter version of writing for this. the only thing that I can come up with is:my @stat = stat($file); my @localtime = localtime($stat[9]); my $year = $localtime[5] + 1900;
but that doesn't work. I've explained this to myself as 'stat' and 'localtime' return lists and not arrays, so you can't use that kind of syntax. Anybody know of a shorter readable way to produce the same result?my $year = localtime((stat($file))[9])[5] + 1900;
PS: I wouldn't mind seeing a golfing-type shorter version :)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: list slice
by bart (Canon) on Jul 21, 2006 at 18:25 UTC | |
Re: list slice
by ikegami (Patriarch) on Jul 21, 2006 at 18:40 UTC | |
by rir (Vicar) on Jul 21, 2006 at 21:20 UTC | |
Re: list slice
by ysth (Canon) on Jul 21, 2006 at 19:05 UTC | |
Re: list slice
by imp (Priest) on Jul 21, 2006 at 22:50 UTC | |
Re: list slice (fewer)
by tye (Sage) on Jul 21, 2006 at 22:35 UTC | |
Re: list slice
by jwkrahn (Abbot) on Jul 21, 2006 at 21:52 UTC |
Back to
Seekers of Perl Wisdom