On 02/24/04 14:18, Randy W. Sims wrote:
On 02/24/04 13:49, rmck wrote:

Help

I need this variable $time to show last hour (00..23) So if hour is 00, I want 23. If hour is 01, I want 00, etc.....
I can run that awk statement on the command line and it works great, but if I try it in the script it fails with an awk syntax error...
Is there a way to look at last hour with $time1 ?? I would rather keep it all perl.....


my $hour = sprintf("%02d", (localtime)[2]-1);

see 'perldoc -f localtime'


BTW, the problem with your original program, specifically the line:


my $time = system("/bin/date +%H | awk -F '{if ($1 == 00) print 23; else if ($1 <= 10) print 0$1 -1; else print $1 -1}'");

is that perl tries to interpolate anything that looks like a variable inside double quotes, so you need to either escape anything starting with $,%, or @ or use single quotes.

Randy.


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to