tricky use of print?

E

Ela

I found that little can be done on debugging a variable on print, after
visiting a page containing the module PadWalker.

I wonder whether in Perl can do something like:

$newline = '\n'

print
foo
$foo

print $newline;


I use the vim editor, in this sense, rapid coding and debugging can achieve.
But i at least know that the newline trick doesn't work...
 
S

szr

David said:
In Perl, single-quotes are not interpolated (meaning $newline is set
to backslash-n). You would need to use double-quotes (or qq{}) to
interpolate \n as a newline.

Or a heredoc :)

print <<_EOF_;
$foo $bar
_EOF_
 
E

Ela

Or a heredoc :)
print <<_EOF_;
$foo $bar
_EOF_

There are too few words in your example and I'm unable to follow/Google. I
guess maybe you are telling something important? thx
 
S

szr

David said:
szr is just showing you an example of how to use a heredoc, which
recognizes the \n at the end of any lines within it (so it's just
another way of printing newlines).

I should of also said, you can either physically have new lines, like:

print <<_EOF_;
A
B
C
_EOF_


Or you can use \n instead:

print <<_EOF_;
A\nB\nC
_EOF_


Or mix and match:

print <<_EOF_;
A
B\nC
_EOF_


Either way you get:

$ perl -e 'print <<_EOF_;
A
B\nC
_EOF_'
A
B
C
 
T

Tad J McClellan

Ela said:
There are too few words in your example and I'm unable to follow/Google. I
guess maybe you are telling something important? thx


See the "<<EOF" section in perlop.pod.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top