Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Problem with file::stat

by thanos1983 (Parson)
on Jun 11, 2015 at 12:24 UTC ( [id://1130026]=note: print w/replies, xml ) Need Help??


in reply to Problem with file::stat

Hello mr19,

The monks have already answered your question. But you can also pass stat values to an array:

Sample:

#!/usr/local/bin/perl use strict; use warnings; use Data::Dumper; my $filename = 'test.txt'; my @array = stat($filename); print Dumper \@array; my $epoch_timestamp = (stat($filename))[9]; print "Epoch seconds: " . $epoch_timestamp . "\n"; __DATA__ $VAR1 = [ 64513, 7741435, 33188, 1, 283683, 6856, 0, 0, 1434023984, 1434023978, 1434023983, 4096, 0 ]; Epoch seconds: 1434023978

Or if you want to use the module:

#!/usr/local/bin/perl use strict; use warnings; use Data::Dumper; my $filename = 'test.txt'; my @array = stat($filename); print Dumper \@array; my $epoch_timestamp = (stat($filename))[9]; my $timestamp = localtime($epoch_timestamp); print "\nEpoch seconds: " . $epoch_timestamp . "\n"; print "Date and time: " . $timestamp . "\n"; statSubRoutine(); sub statSubRoutine { use File::stat; my $timestamp = (stat($filename)->mtime); my $localTimeStamp = localtime($epoch_timestamp); print "\n\$timestamp: " . $timestamp . "\n"; print "\$localTimeStamp: " . $localTimeStamp . "\n"; } __DATA__ $VAR1 = [ 64513, 7741354, 33188, 1, 283683, 6856, 0, 0, 1434028480, 1434028479, 1434028479, 4096, 0 ]; Epoch seconds: 1434028479 Date and time: Thu Jun 11 15:14:39 2015 $timestamp: 1434028479 $localTimeStamp: Thu Jun 11 15:14:39 2015

Update: Including conversion epoch seconds to human readable form.

Hope this helps.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-24 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found