Reputation: 2064
I tried this example:
#!C:/Perl64/bin/perl.exe
$mickey = "Hi i'm Mickey";
$pluto = "Hi i'm Pluto";
print <<EOF;
$pluto
Hi i'm Goofy
$mickey
EOF
print <<'EOF';
$pluto
Hi i'm Goofy
$mickey
EOF
Obtaining the following output:
Hi i'm Pluto
Hi i'm Goofy
Hi i'm Mickey
$pluto
Hi i'm Goofy
$mickey
I want to obtain the same behaviour using whitout using << operator
. So i tried this other one:
#!C:/Perl64/bin/perl.exe
$mickey = "Hi i'm Mickey";
$pluto = "Hi i'm Pluto";
print STDOUT "$pluto
Hi i'm Goofy
$mickey";
that actually prints:
Hi i'm Pluto
Hi i'm Goofy
Hi i'm Mickey
How can I escape EACH perl special char?
I tried using print 'STDOUT' ...
having not what I was looking for.
Upvotes: 1
Views: 80
Reputation: 385849
print <<"EOF"; # <<EOF is short for <<"EOF"
$pluto
Hi i'm Goofy
$mickey
EOF
print <<'EOF';
$pluto
Hi i'm Goofy
$mickey
EOF
is equivalent to
print
"$pluto
Hi i'm Goofy
$mickey
";
print
'$pluto
Hi i\'m Goofy
$mickey
';
Note the parallel between the quotes used.
Unfortunately, because the delimiter is present in the literal, you must escape it.
Upvotes: 2
Reputation: 206699
Use single quotes (or q/STRING/
quote operator) rather than double quotes if you don't want interpolation to happen:
$mickey = "Hi I'm Mickey";
$pluto = "Hi I'm Pluto";
print STDOUT q{$pluto
Hi I'm Goofy
$mickey};
STDOUT
is redundant here too, that's the default. print 'foo $bar';
would be enough.
Upvotes: 3
Reputation: 374
How can I escape EACH perl special char?
Use "\" to do that
my $var = "test";
print "\$var\n";
print "$var\n";
Output:
$var
test
Upvotes: 0