CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Porting code over to Unix



Jul 31, 2005, 2:41 PM

Post #1 of 3 (625 views)
Porting code over to Unix Can't Post

I have the following routine running in the Windows/NT environment, which returns the last modified date/time of the file passed:

sub get_last_modified {
my $file = shift;
my $date = scalar localtime((stat($file))[9]);
$date =~ s/ +/ /g;
return ($date);

I tried to port it to the Unix environment. However, it always returns “Wed Dec 31 16:00:00 1969”. Does anyone know what needs to be done to make this work? Also in general, what should I be watching out for when porting code from Windows/NT environment to Unix?

Thanks in advnace for your help.

Thaumaturge / Moderator

Aug 2, 2005, 2:02 AM

Post #2 of 3 (618 views)
Re: [tschau] Porting code over to Unix [In reply to] Can't Post

Your code works fine for me. I'm pretty sure it's not a Windows/Unix portability issue.

It looks like that "stat" call is returning -32400.

$ perl -le 'print scalar localtime(-32400)' 
Wed Dec 31 16:00:00 1969

Is there something strange about the dates on your filesystem?

What do you get if you just try "ls -l" for one of the files? What do you get for "perl -le 'print +(stat "yourfilehere")[9]'"?

Dave Cross, Perl Hacker, Trainer and Writer
Get more help at Perl Monks


Aug 3, 2005, 6:53 AM

Post #3 of 3 (610 views)
Re: [tschau] Porting code over to Unix [In reply to] Can't Post

Thanks for the prompt response. With the help of your questions, and playing with the code some more, I was able to determine that the problem was not with the code, but that the value of the file name somehow did not get passed to the routine. Now it is working as expected.

Thanks once again for your help!


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives