Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: passing a command line argument

by naikonta (Curate)
on Oct 04, 2007 at 16:17 UTC ( #642697=note: print w/ replies, xml ) Need Help??


in reply to passing a command line argument

As bart points out, it can't happen. It could be the shell that trying to replace what it considers special (meta) characters in the $string. You can use quotemeta to escape those characters or using the equivalent escape sequences such as \Q.

$ ls hello $ perl -e 'my $dir = q(not$socooldir); system "mkdir $dir" and die "ex +ecution failed\n"' $ ls hello not $ perl -e 'my $dir = q(not$socooldir); $dir = quotemeta $dir; system " +mkdir $dir" and die "execution failed\n"' $ ls hello not not$socooldir $ perl -e 'my $dir = q(not$socooldir); system "mkdir \Q$dir" and die " +execution failed\n"' mkdir: cannot create directory `not$socooldir': File exists execution failed

Of course, perl has its own mkdir function, internally. Please note that the third execution fails because directory already exists, indicating that \Q$dir and quotemeta $dir result in the same directory name.

One more thing, please don't use `shellcmd args` in void context, because you ask for something to return but effectively discard it. Assign it to a scalar or an array to capture the output if you want it so.

my @lines = `shellcmd args`; # list context my $line = `shellcmd args`; # scalar context

Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!


Comment on Re: passing a command line argument
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2014-12-27 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls