The problem is that in case if $string contains characters like $ or @ or % then these values are getting replaced by the perl keys.
No it doesn't.

"Interpolation", as it's called, goes only one level deep. Hence, it's the string contents of the variable $string that is inserted in the command line. Contrary to what you seem to believe, nothing else is replaced.

And %hash is never interpolated in a string. Never.

What may happen is that the invoked shell may treat shell metacharacters in this command line special (for example, replace parts of the command line by environment variables). But that's not Perl's fault. That's why $d may appear to disappear from your command line.

Use of String::ShellQuote may help you in alleviating that problem.


In reply to Re: passing a command line argument by bart
in thread passing a command line argument by s_gaurav1091

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.