Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: not able to get last modified time of a file

by ack (Deacon)
on Jan 28, 2011 at 16:07 UTC ( [id://884870]=note: print w/replies, xml ) Need Help??


in reply to not able to get last modified time of a file

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-23 14:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found