http://qs321.pair.com?node_id=1027641

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

Replies are listed 'Best First'.
Re: Making escape (\) ordinary in double quotes
by AnomalousMonk (Archbishop) 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.'
Re: Making escape (\) ordinary in double quotes
by 2teez (Vicar) 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 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;