#!/usr/bin/perl
($sec, $min, $hour, @junk) = localtime(time);
print "$hour:$min$sec\n";
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
like this in the file: 12:12:00? or like this: 12:12? Or like this: 12:12:00am?
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
This doesn't actually change it in the file.... but it writes a new file, you can just easily change the variable on the second open to be the file it read from, however. I'm sure that Rashakil or Narue will show you a much more effecient method, but for now this works:
#!/usr/bin/perl
$timefile = "times.txt";
$newfile = "newtimes.txt";
open(FH, "$timefile");
while (<FH>) {
chomp;
($tm, $pod) = split(/ /, $_);
($hr, $min, $sec) = split(/:/, $tm);
if ($pod eq "PM") {
$hr = $hr + 12;
$tm = "$hr:$min:$sec";
} else {
$tm = "$hr:$min:$sec";
}
push @new_times, $tm;
}
close(FH);
open(FH, ">$newfile");
foreach $ntime (@new_times) {
print FH "$ntime\n";
}
close(FH);
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
Glad to have tried to help.... if you could have posted that information previously, I would have done a better job. Sorry for the miscommunication.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
just stick an if in the code...for example:
($hr, $min, $sec) = split(/:/, $timevariable);
if ($hr eq "24") {
$hr = "00";
}
$timevariable = "$hr:$min$sec";
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
That's 24 hour format right? 12 is noon, and 0 is midnight.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215