Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Escaping characters in one-liners

by Tanktalus (Canon)
on Mar 12, 2005 at 02:33 UTC ( #438864=note: print w/ replies, xml ) Need Help??


in reply to Escaping characters in one-liners

Technically, this is more of a shell question than a perl question. That said, I can understand that it is highly relevant to perl programmers since we seem to take huge pride in our one-liners. ;-)

For Bourne-shell and derivitives (such as ksh and bash), you simply need to put your program in single quotes, and not use single quotes inside your program.

I think it's the same for C-shell, but I'm not really a C-shell expert.

For CMD.EXE (both Win32 and OS/2), you need to use double quotes, and not use double quotes inside your program. Since double quotes interpolate everything, you may want to. Don't - use $/ instead of "\n", e.g., perl -e "print 'foo', $/". For other interpolation, use qq, e.g., perl -e "print qq(foo\n)". You also want to be careful with percent signs - avoid them if you can. If you can't, I think doubling them works - %% probably is replaced with a single %.

I'm sure others will expand on this - but I've not had any need of more than this. I rarely use Windows, and when I have to, I don't need to do any modulos or print percent signs.


Comment on Re: Escaping characters in one-liners
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (13)
As of 2015-07-03 13:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (53 votes), past polls