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

Hi all

I have script that I need to write using data embedded in the application. Part of this data contains the string */. The * could represent several hundred entries that change on a daily basis.

Here is what I have (The array is longer than just the 1 element)

my @testqueue = (10.10.10.10); &pause; sub pause { my $pback = "/usr/sbin/cmd"; my $set = "pause queue"; while (@testqueue){ my $out = `$pback $set */$testqueue[0]`; print "$out"; shift @testqueue; } }
The real command looks like this:
$cmd pause queue */10.10.10.10

Thanks for your help!

xj

Replies are listed 'Best First'.
Re: Using */ with backticks in perl
by ikegami (Patriarch) on Feb 09, 2010 at 23:37 UTC

    You need to convert the strings to which $pback, $set and "*/$testqueue[0]" evaluate into shell literals. Or simply avoid the shell entirely.

    open(my $pipe, '-|', ( $pback => ( $set, "*/$testqueue[0]" ) ) or die("Can't launch $pback: $!\n"); my $out = ''; { local $/; $out = <$pipe>; }
Re: Using */ with backticks in perl
by chromatic (Archbishop) on Feb 09, 2010 at 23:35 UTC

    I'm not sure I understand your question. Are you getting shell errors? (If so, escape the * with a backslash.)

Re: Using */ with backticks in perl
by cdarke (Prior) on Feb 10, 2010 at 11:20 UTC
    Assuming UNIX or Linux, the shell is interpreting * as a glob construct (wildcard) and expanding it to all the file names in the current directory. Either enclose it in quotes or place a \ in front.
      If you want the shell to see a backslash there, better put two of them before the star. One for Perl, one for the shell.