There's more than one way to do things | |
PerlMonks |
Re: not able to get last modified time of a fileby ack (Deacon) |
on Jan 28, 2011 at 16:07 UTC ( [id://884870]=note: print w/replies, xml ) | Need Help?? |
The module stats is a built-in function of Perl as Ratazong points out; so you don't need File::stats and as Ratagong also points out, using File::stats causes the built-in stats to be overridden which is probably not what you'd want overall...but that's just MHO. The stats() function returns an array reference, not the array itself. So you'll have to derefference the result of stat() before you then try to access element 9. That is what I believe ikegami was showing you. Also, in your included code snippet you left out the brackets around 9...but I presume that was just an oversight in what you posted, not as it occured in your code. UPDATE: I inadvertantly posted that the fuction is stats(). It should be stat() I believe. Sorry. UPDATE 2: Well, now I'm confused. When I was trying the case that the OP posted, I found that stat() returned an array reference (hence, my posted response). But when I was playing around with it a little further, I find that, indeed, I can use the construc my $mtime = (stat($i))[9] to get the last modified time. And I can't get it to return the array reference now. So now I'm a bit confused as this implies that the OP's only mistake, as far as I can tell, was that there were no enclosing square brackets around his array element number. Once I corrected that, the OP's code works for me.
ack
Albuquerque, NM
In Section
Seekers of Perl Wisdom
|
|