Re: error on simple system command
- From: Jenda@xxxxxxxxxxx (Jenda Krynicky)
- Date: Tue, 27 Nov 2007 01:00:13 +0100
To: beginners@xxxxxxxx
From: lerameur <lerameur@xxxxxxxxx>
Subject: error on simple system command
Date sent: Mon, 26 Nov 2007 13:05:53 -0800 (PST)
Organization: http://groups.google.com
Hello,
I am trying to use this two line script. The command by itself works,
when I run this script, I get error message:
Use of uninitialized value in concatenation (.) or string at ./
find_date.pl line 8.
line 8: my $file_to_print = system "ls -lrt /test/*log | tail -1 |
awk {'print $9'}";
print $file_to_print;
then after the error message an erroneous output, showing the correct
file but with all the fields...
how Do I get the script to function as if I where to implement the
command directly.
Thanks,
There are at least two problems with the code.
1) The $9 is evaluated by perl, not passed as is to awk. You have to
escape $ by prepending a backslash if you want it to be treated
literally in a doublequoted string.
2)system() doesn't return the text printed by the program you run. It
returns "the exit status of the program as returned by the wait
call". That is, a number.
I think you wanted to use
`ls -lrt /test/*log | tail -1 | awk {'print \$9'}`
Please have a look at
perldoc -f system
and
perldoc perlop
(search for `STRING`)
Of course you should not be running external programs if all you want
is to find out the name of the last *log in a directory.
Jenda
===== Jenda@xxxxxxxxxxx === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
.
- Follow-Ups:
- Re: error on simple system command
- From: Lerameur
- Re: error on simple system command
- References:
- error on simple system command
- From: Lerameur
- error on simple system command
- Prev by Date: Script to read the contents of a directory
- Next by Date: Re: Script to read the contents of a directory
- Previous by thread: Re: error on simple system command
- Next by thread: Re: error on simple system command
- Index(es):
Relevant Pages
|