Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Re: using qx{}

by CheeseLord (Deacon)
on Sep 04, 2001 at 05:07 UTC ( [id://109974]=note: print w/replies, xml ) Need Help??


in reply to Re: using qx{}
in thread using qx{}

While you are correct in your statements about interpolation, your second system call will not store anything in $foo[0] besides 0 (or, possibly, 256). The difference between system and qx is quite important - the former returns the return value of the code's execution, and the latter will return the output from the code's execution.

Should you desire to keep the string passed to a qx from interpolating, use single quotes as the delimiter, like so:

@foo = qx'echo $HOME';

Which should store "/home/cheesy\n" or something like that in $foo[0]. I hope that helps...

Update: Changed emphasis in a few places.

Update #2: The node I replied to has had its content altered in a way that makes this node make no sense... the original second system call was as follows:

@foo = system('echo $username[0]');

I hope that clears up any confusion.

His Royal Cheeziness

Replies are listed 'Best First'.
Re: Re: Re: using qx{}
by Rhandom (Curate) on Sep 05, 2001 at 01:38 UTC
    You are correct in your statements about system, qx, and the backtick (`) operator. However, there is little syntactical difference between your example with qx'', and qx{}. Both are correct and will return the result of execution. The previous poster, didn't really mention system at all. (Just observing)

    #!/usr/bin/perl -w @username = qw(nobody anybody); @foo = qx{ echo $username[0] }; chomp($foo[0]); print "'$foo[0]'\n"; @foo = qx{ echo \$username[0] }; chomp($foo[0]); print "'$foo[0]'\n"; @foo = qx' echo $username[0] '; chomp($foo[0]); print "'$foo[0]'\n"; # prints out #'nobody' #'[0]' #'[0]'


    my @a=qw(random brilliant braindead); print $a[rand(@a)];

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2024-03-28 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found