CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
quotes within qx() -removing

 



regex2012
User

Aug 18, 2016, 9:28 AM

Post #1 of 3 (1936 views)
quotes within qx() -removing Can't Post

I have a command like this:


Code
@array1 = qx(/usr/sbin/prinfind -start 08/01/2016 -end 08/16/2016 |awk '{print $2}')

It keeps printing quotes around words. I tried to use sed within the parenthesis to take out the quotes like this:


Code
sed 's\"//g'

but this does not work. I can't escape the quotes within the qx command. Does anyone know how? If the quotes print out they cause the array to feed improper data to other print statements and commands


FishMonger
Veteran / Moderator

Aug 18, 2016, 10:00 AM

Post #2 of 3 (1932 views)
Re: [regex2012] quotes within qx() -removing [In reply to] Can't Post

Are you saying it's putting quotes around the words in the command or the output of the command?

Can you show us the lines?

Maybe instead of using the qx() operator, you should look into using IPC::Open2 or IPC::Open3.
http://search.cpan.org/~rjbs/perl-5.24.0/ext/IPC-Open3/lib/IPC/Open2.pm
http://search.cpan.org/~rjbs/perl-5.24.0/ext/IPC-Open3/lib/IPC/Open3.pm


Laurent_R
Veteran / Moderator

Aug 18, 2016, 1:43 PM

Post #3 of 3 (1923 views)
Re: [regex2012] quotes within qx() -removing [In reply to] Can't Post

Your syntax for sed is incorrect: you need a slash between the "s" and the text to be replaced:


Code
$  echo ' AA " BB " A' | sed -e  's/"//g' 
AA BB A

or simply:

Code
$  echo ' AA " BB " A' | sed  's/"//g' 
AA BB A


And, as you can see, no need to escape the quote mark.

But besides that, I don't think it is a good idea to use sed or awk in a Perl program: Perl can do everything that sed or awk can do, usually better, more efficiently and with more functionality, and without the need to fork a shell for that.

It could be something like this:


Code
@array1 = map s/"//g, qx(...);

or:

Code
@array1 = map {s/"//g} qx(...);



(This post was edited by Laurent_R on Aug 18, 2016, 1:45 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives