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

passing variables

by rudeb0y (Novice)
on Jan 09, 2006 at 16:53 UTC ( [id://521993]=perlquestion: print w/replies, xml ) Need Help??

rudeb0y has asked for the wisdom of the Perl Monks concerning the following question:

I'm having problems passing a variable. Below is a snippet.
system ('tremove @host:$ep');

@host is NOT an array, it's actually a parameter (hence the '). However, $ep is a variable I'm trying pass. But with the ('), it's not capturing the actual value.

I've tried $[ep] and [$ep] to no avail. I know it's something simple.

Replies are listed 'Best First'.
Re: passing variables
by swkronenfeld (Hermit) on Jan 09, 2006 at 17:00 UTC
    Variables enclosed in single quotes don't get interpolated. So you need to enclose in double quotes, but escape the ampersand on the array.

    system ("tremove \@host:$ep");

      It's worth pointing out that you shouldn't use variables in system calls without knowing for sure what the variables contain. If you aren't positive that what's in $ep is safe, you are taking a huge risk.

      You should read the section on Taint mode and @INC in perlsec (and, in fact, all of perlsec is good reading) before letting that line into a public/production environment.

      Yeah, I'm paranoid -- once bitten, twice shy and all that.

      <-radiant.matrix->
      A collection of thoughts and links from the minds of geeks
      The Code that can be seen is not the true Code
      "In any sufficiently large group of people, most are idiots" - Kaa's Law
      thx...that worked. I knew it wuz gonna be simple.
Re: passing variables
by explorer (Chaplain) on Jan 09, 2006 at 17:07 UTC
Re: passing variables
by talexb (Chancellor) on Jan 09, 2006 at 16:59 UTC

    As someone has no doubt already pointed out, the single quote doesn't do variable interpolation. You probably want

    system ("tremove @host:$ep"); # WRONG -- should be \@host
    instead.

    Update: Sorry, as has been pointed out -- the '@' should be escaped with a leading '\'. That'll teach me to post something, then wander off to continue my work day.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      system ("tremove @host:$ep");

      That solves one problem by creating another. You've solved the problem of $ep not interpolating, but you've created the problem of @host interpolating, when the OP stated it's not intended to be a variable.

      You could use either of the following techniques:

      system( 'tremove @host:' . $ep ); system( "tremove \@host:$ep" );

      Dave

      You meant to escape the @ as \@ but didn't.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-03-28 08:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found