Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: stat a file

by moritz (Cardinal)
on May 04, 2013 at 05:50 UTC ( #1031990=note: print w/replies, xml ) Need Help??


in reply to stat a file

You can either store the result of stat in an array:

my @stat = stat $filename; say $stat[5];

or you can use the File::stat module, in which case you get an object back:

use File::stat; my $stat_obj = stat $filename; print $stat_obj->mtime;

But you have to decide for one way or another -- mixing them is what led to your confusion in the first place.

Replies are listed 'Best First'.
Re^2: stat a file
by pelos (Initiate) on May 04, 2013 at 06:22 UTC
    thanks I will give it a try. do you recommend to stick to one particular method? or doesn't really matter?

      stat has slightly less overhead, but File::stat is slightly more readable. File::stat is part of the Perl core since 5.004 (released 1997-05-15), so it's quite safe to assume that File::stat is available even on older Perl installations.

      File::stat has some minor problems, mainly with the implicit $_ and the special handle _, see "Bugs" in File::stat. Also, the filetest operators -t, -T, and -B are not implemented in File::stat. This is documented in "Errors".

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1031990]
help
Chatterbox?
LanX chjuman !
[Eily]: do you pronunce that /xju:mən/ then ?
[Eily]: that's not what I'd call a silent h :)
[LanX]: see soundfile https://en. wiktionary.org/ wiki/human# Pronunciation
[Your Mother]: Just Another Perl 'Acker.
[LanX]: I pronounce it 'juːmən'
[Your Mother]: Hey, let's not bring antisemitism into the conversation.
[LanX]: for centuries posh English speakers tried to approach French, that's where all the trouble starts
[Eily]: Just another Perl coeurs
[Eily]: (perl with hearts, 'Acker with a French accent is pronunced like coeurs)

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2017-03-27 17:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.