Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: how to use perl variable in system command to run on unix

by chromatic (Archbishop)
on Sep 03, 2013 at 16:36 UTC ( #1052142=note: print w/ replies, xml ) Need Help??


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.


Comment on Re: how to use perl variable in system command to run on unix
Select or Download Code
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 !!!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1052142]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (16)
As of 2014-08-20 15:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (116 votes), past polls