Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: system() and qx comparison

by Kc12349 (Monk)
on Sep 27, 2011 at 22:00 UTC ( #928193=note: print w/replies, xml ) Need Help??


in reply to system() and qx comparison

Remove the single quotes from around $LANG in your second form or replace them with double quotes.

qx is another form for backticks, which in perl will capture the return from the system call.

my $return = qx{echo $LANG}; say $return;

Replies are listed 'Best First'.
Re^2: system() and qx comparison
by didess (Sexton) on Sep 27, 2011 at 22:28 UTC
    thanks for your answer;

    but, if replace single quotes by doubles quotes with qx, $LANG will be resolved as a Perl variable, not as a shell environment variable

    This little code will show it clearly:
    cat essaiQX.pl #!/usr/bin/perl my $LANG = "script internal"; system('echo $LANG'); system('echo','$LANG'); my @out = qx "echo $LANG"; chomp(@out); print "out=@out\n"; my @out = qx' echo $LANG '; chomp(@out); print "out=@out\n";

    it's output is :

    ./essaiQX.pl fr_FR.UTF-8 $LANG out=script internal out=fr_FR.UTF-8

    In fact i'd like to pass parameters to the command (the "echo" program in this little example), with possibly $, *, and such characters which the shell interpretes. while avoiding a large collection of antislashes. May be, it's not possible with qx and I must use system(). That's what I'd like to know</p

      If you want the environments LANG variable, use $ENV{LANG}.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://928193]
help
Chatterbox?
[Discipulus]: uh neat karl!
[Your Mother]: Both good things to try, thank you!
[karlgoethebier]: Discipulus: see my scratchpad for <<>>...
[Discipulus]: thanks, anyway perl -MO=Deparse -E "while (<<>>) {print;}" gives error to me

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2017-07-21 08:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (319 votes). Check out past polls.