Hi Adrian,
> running the command:
> date|awk '{print $2,$3}'
>
> provides me with the output I require (i.e. the month and day, May 6).
>
> however, when I try to call this from within a perl script:
> system("date|awk '{print $2,$3}'");
>
> I get:
> awk: syntax error near line 1
> awk: illegal statement near line 1
I would guess that Perl substitutes the variables $2 and $3 before passing
them to awk. Try printing the command before sending it to see if it�s ok:
my $command = "date|awk '{print $2,$3}'";
print "gonna send >>$command<<\n";
system($command);
If that�s the case, you might be able to fix this by escaping the dollar
signs:
my $command = "date|awk '{print \$2,\$3}'";
>
>
> any ideas? alternatively, does anyone have another way to
> generate the date
> in this format that I can assign to a variable?
>
Anyway - using a system call for getting the date look like overkill to me.
I'd use something like this:
my (undef, undef, undef, $mday, $mon) = localtime();
printf "Today is %s $mday\n",
(qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[ $mon ];
See perldoc -f localtime for detailed information.
HTH,
Philipp
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>