Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
No such thing as a small change
 
PerlMonks  

Re: How do I print a quote with a perl one liner on dos?

by thinker (Parson)
on Mar 23, 2005 at 09:55 UTC ( #441724=note: print w/ replies, xml ) Need Help??


in reply to How do I print a quote with a perl one liner on dos?

hi tphyahoo,

Are you sure you have asked the correct question? If so, this will do what you want

perl -le "print chr 34"

thinker


Comment on Re: How do I print a quote with a perl one liner on dos?
Download Code
Re^2: How do I print a quote with a perl one liner on dos?
by tphyahoo (Vicar) on Mar 23, 2005 at 10:07 UTC
    Thanks Thinker, I guess I didn't really ask the right question.

    What I really want is to have the same nice quoting behaviors in my one liners that I am used to in perl. Dos is weird with quotes. I was wondering if there is some kind of workaround.

    I would like to be able to do

    perl -e "$helloWorld = '"hello world"'; print "$helloWorld"";
    and have it "just work" (ie, print hello world with double quotes around it) without being in escape-with-backslash hell, ie,
    perl -e "$helloWorld = '\"hello world\"'; print "$helloWorld"";

    as, with gellyfish's help, I now know to do.

    I guess maybe this really isn't *that* "hellish" but it isn't anywhere near as heavenly as perl outside of the dos shell. So, if there is some other trick...

      when you print $whatever you don't need to print "$whatever" unless you want to print "$whatever and $something else in the same string" - that'll at least save you two backslashed double quotes.

      that said, the point is that with the windows command shell the double quote is the string quoting character so in order not to have your perl -e code string stop at the next ", you have to escape it for the shell's benefit. to illustrate - escaping outside of the -e code: perl -e "print qq(@ARGV)" \"hello world\"

      I guess the trick is that you use single quotes instead ;)

      perl -e "$helloworld = qq('hello world'); print $helloworld"

         larryk                                          
      perl -le "s,,reverse killer,e,y,rifle,lycra,,print"
      

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2014-04-19 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (478 votes), past polls