Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Escaping characters in one-liners

by saintmike (Vicar)
on Mar 12, 2005 at 08:07 UTC ( #438888=note: print w/ replies, xml ) Need Help??


in reply to Escaping characters in one-liners

Getting the quotes right can be quite daunting, that's why there's help via Sysadm::Install from CPAN: Let's whip up a script one_liner really quickly:

#!/usr/bin/perl # one_liner - produce a perl one-liner out of perl code use Sysadm::Install qw(:all); my $in = join "", <>; $in =~ s/\n/ /g; print "perl -e ", qquote($in, ':shell'), "\n";

Now, if you call one_liner without arguments, it'll wait for code to be typed into STDIN, terminated by CTRL-D, and spit out the one-liner right after:

$ one_liner print "hello\n"; print "world\n"; ^D perl -e "print \"hello\\n\"; print \"world\\n\"; "

Produces properly escaped one-liners out of any messy perl code you paste in.


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://438888]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (14)
As of 2015-07-06 14:05 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 (75 votes), past polls