in reply to how to use perl variable in system command to run on unix

$grep_date won't interpolate in the singly-quoting q() construct. When you change to a double-quoting construct, be sure to escape the dollar sign in awk's $9 argument.


Improve your skills with Modern Perl: the free book.

Replies are listed 'Best First'.
Re^2: how to use perl variable in system command to run on unix
by tousifp (Novice) on Sep 03, 2013 at 16:47 UTC

    Thanks Chromatic. I changed this line as said : my $files=system(qq(cd /waslogs1/vfoneLog/cposapp && ls -lrt | grep -i "$grep_date" | awk '{ print \$9 }' > /home/cpos/CRM_Reports/timelogic/filelist.txt)); Its working now. But can you explain me what was the problem with previous line.

    And what if I use :
    my $cmd=q(cd /waslogs1/vfoneLog/cposapp && ls -lrt | grep -i "$grep_da +te" | awk '{ print $9 }' > /home/cpos/CRM_Reports/timelogic/filelist. +txt); my $files=system($cmd);

    This is still not working

      q does not expand variables, for that you need qq e.g.
      % perl -E '$x = "hello"; say q($x)' $x % perl -E '$x = "hello"; say qq($x)' hello

        Thank you very much. But why $9 is escaped? Me new to perl !!!