View Single Post
  #2 (permalink)  
Old August 25th, 2009, 01:26 AM
Leigh Leigh is offline
Registered User
 
Join Date: Aug 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My guess is that you are not passing a valid filename to the sub.
Are you using strict and warnings?

Code:
use strict;
use warnings;
use Time::Local;

sub getTime
{
   my $myfile=shift;
   my $filestat = (stat($myfile))[9];
   my $mystamp = scalar(localtime($filestat));

   print "File Stamp " . $mystamp;
}
getTime("timestamp.pl");
Gives me:
Code:
C:\Temp>perl timestamp.pl
File Stamp Tue Aug 25 15:23:37 2009
But if I remove the 'use strict', 'use warnings' and 'my $myfile=shift' lines, I get the same output as you are getting, because this line:
Code:
my $filestat = (stat($myfile))[9];
has nothing to do a stat() on.
Reply With Quote