Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

The particular characters that you need to escape are dependent upon the shell, not on perl. For the most part, you can just encase the perl string to be evaluated in single quotes in a unix shell, and make sure that you don't use single quotes in your perl. (I don't know about windows quoting) :

perl -e 'whatever to execute;'

You can also use -l (that's a lower case L), so you can send a command quickly without the shell messing with it. (but again, this won't work in the times when you want the shell to do its magic, and it also keeps you from using the shell's abilities to repeat the command).

If there are times when you want to use shell variables in your line, you can either export them and reference them in perl as $ENV{"NAME"} rather than $NAME or you can end the quoting, use the variable, and then start it back up again:

perl -e 'print "you are logged in as $ENV{USER}\n";' perl -e 'print "you are logged in as '$USER'\n";'

The only thing that's really tricky is when you're trying to mix perl and shell commands ... which I'd advise not doing from the shell, as you can't always be sure of the output, and calling it from within perl.


In reply to Re: Escaping characters in one-liners by jhourcle
in thread Escaping characters in one-liners by Willworker

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (5)
    As of 2014-12-25 07:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

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





      Results (159 votes), past polls