Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Making escape (\) ordinary in double quotes

by sg (Pilgrim)
on Apr 09, 2013 at 04:36 UTC ( #1027641=perlquestion: print w/ replies, xml ) Need Help??
sg has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

Rather than writing:

{ my $foo = "Ignore the \\slash, expand $boo."; }

is it possible to do something like:

{ # do something to get perl # to treat '\' as an ordinary character # so that one may write: my $foo = "Ignore the \slash, expand $boo."; }

Thanks

Comment on Making escape (\) ordinary in double quotes
Select or Download Code
Re: Making escape (\) ordinary in double quotes
by Rahul6990 (Beadle) on Apr 09, 2013 at 05:31 UTC
    You can concatenate the variable along with the string containing '\' in (') single quote. Ex

    my $foo  =  "Ignore the \slash, expand '.$boo;
Re: Making escape (\) ordinary in double quotes
by 2teez (Priest) on Apr 09, 2013 at 06:10 UTC

    You can use q/STRING/

     my $foo  =  q{Ignore the \slash, expand} . $boo;

    You can check Quote-Like-Operators

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
Re: Making escape (\) ordinary in double quotes
by AnomalousMonk (Abbot) on Apr 09, 2013 at 09:34 UTC

    sprintf does not alter the interpolation behavior of a double-quoted string, but it does provide all the interpolation capability of double-quoting – and more! See the many format specifiers in the docs.

    >perl -wMstrict -le "my $foo = 'Foo'; my $bar = 'Bar'; ;; my $x = sprintf 'ignore \slash, expand %s, %s.', $foo, $bar; print qq{'$x'}; " 'ignore \slash, expand Foo, Bar.'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1027641]
Approved by 2teez
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-09-20 06:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (155 votes), past polls