Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Welcome to the world of escaping! :)

If you have an end delimiter and you want to allow this end delimiter to appear literally you need to escape it, hence \' => '

But if you're escaping, you're also needing an escape character, which has also to be escaped when used literally, hence \\ => \

And thats it, nothing else needed within the single quotes family of q{} with a free choice of end delimiters.

And now, if you think that perl sucks try emacs lisp, which only supports double quotes! In elisp regexes suffer from a ugly disease called slasheritis².

Luckily you can use heredocs, because there is no delimiter that need to be escaped. And if you don't like the newlines then chomp:

$foo = <<'__HERE__'; \\some.address.or.whatever\subdir\ __HERE__ chomp $foo; print ">", $foo ,"<"; # >\\some.address.or.whatever\subdir +\<

I suppose you don't wanna put multiple path in a long heredoc? ¹

So why don't you use a character like / as placeholder?

sub s2b { # slash to backslash (my $str = shift) =~ tr#/#\\#; return $str; } my $path = s2b '//some.address.or.whatever/subdir/';

Just don't blame Perl for M$ decision to use an escape character for separating paths. =)

Cheers Rolf

update

fixed code for s2b()

footnotes

¹) you could read them into a hash defined by preceded hash keys.

use Data::Dump; sub parsepath { my $str=shift; return split /\s+/,$str; } my %path = parsepath <<'__HERE__'; install \\some.address.or.whatever\subdir\ deinstall \\other.address.or.whatever\subdir\ __HERE__ dd \%path;

==>

{ deinstall => "\\\\other.address.or.whatever\\subdir\\", install => "\\\\some.address.or.whatever\\subdir\\", }

²) yes, it insults the eyes!!!


In reply to Re: Single Quotes - how to avoid any escape processing? by LanX
in thread Single Quotes - how to avoid any escape processing? by temporal

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-20 01:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found