John W. Krahn wrote:
jet speed wrote:

I have a simple code below,

###################################
#!/usr/bin/perl

use strict;
use warnings;

my @list =( '/usr/data/logs' , '/usr/data1/logs');
foreach (@list)
{
print "$_ \n";

system "(/usr/bin/find "$_" -mtime 3 -print -exec ls '{}' \;)";
}
################################################

I am not sure how to get the $_ value inside the system command, any tips
would be most helpful.

The escape \ in front of the semicolon is being interpolated away by perl before the shell sees it so you need to escape it:

system "(/usr/bin/find "$_" -mtime 3 -print -exec ls '{}' \\\;)";

And you need to escape the quotes around $_ as well:

system "(/usr/bin/find \"$_\" -mtime 3 -print -exec ls '{}' \\\;)";

Or use different quotes for the whole string:

system qq[(/usr/bin/find "$_" -mtime 3 -print -exec ls '{}' \\\;)];


Or you need to bypass the shell altogether:

system '/usr/bin/find', $_, '-mtime', 3, '-print', '-exec', 'ls', '{}', ';';


(You do realize that "-print" and "exec ls {} \;" do the same thing?)


John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to