David wrote:
I am trying to get 081129 into $dayStamp.
#!/usr/bin/perl -w
use strict;
my $dayStamp;
$dayStamp = `date +\'%y%m%d\'` && die "Failure!";
You have three problems with that statement:
1) The '=' operator has higher precedence than the '&&' operator so you
need to either enclose the assignment in parentheses or use the low
precedence 'and' operator.
2) `date +\'%y%m%d\'` returns TRUE on success and FALSE on failure so
using the '&&' operator means that the program will die when `date`
worked correctly.
3) You are calling an external program to do something that Perl
provides built-in functions for.
my $dayStamp = do {
my ( $day, $month, $year ) = ( localtime )[ 3, 4, 5 ];
sprintf '%02d%02d%02d', $year % 100, $month + 1, $day;
};
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/