Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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
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 !!!

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 meditating upon the Monastery: (9)
As of 2015-07-30 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls