I'd like to know the year (in localtime) a file was last modified.
I know I can do that with:
my @stat = stat($file);
my @localtime = localtime($stat[9]);
my $year = $localtime[5] + 1900;
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 $year = localtime((stat($file))[9])[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?
PS: I wouldn't mind seeing a golfing-type shorter version :)
In reply to list slice
by eXile
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|