Update Based on -M

Z

zoomcart.com

I have user files i need to update if they haven't been updated since
01/03/09. the code i have below thinks they aren't old enough. what am
i doing wrong? thanks in advance for your help.

$oldage=(-M "members/$user/files/product.txt");
if ($oldage < "01/03/09") {
print qq~yep-it's older~;
&update;
}
else{
print qq~nope~;
}
 
A

Andrzej Adam Filip

zoomcart.com said:
I have user files i need to update if they haven't been updated since
01/03/09. the code i have below thinks they aren't old enough. what am
i doing wrong? thanks in advance for your help.

$oldage=(-M "members/$user/files/product.txt");
if ($oldage < "01/03/09") {
print qq~yep-it's older~;
&update;
}else{
print qq~nope~;
}

-M return "age of file in days" counting from script start.

Use stat function to get file modification "time in unix format".
Use str2time funtion in Date::parse module to convert "date string" into
"time in unix format".
 
N

News123

There's some problems with you attempt

1.) $oldage does not return the date as a string (see previous response
from Anfrzej

2.) Even if $oldage would return a string, then you had to make a string
comparison with lt and not a numerical comparison with '<'

3.) Performaing a string comparison on dates with the format 'mm/dd/yy'
would not compare correctly as for example
'01/04/08' lt '01/03/09' would return false, though it should be true.

tghe best format for date strings if you want to sort / compare is
something like 'yyyy-mm-dd'


You can use the module Time::Local to convert a given date into
'seconds since the system epoch'
http://perldoc.perl.org/Time/Local.html


bye


N
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top