print statement spanning multiple lines

V

Voitec

Hi,

St00pid question time:
How can I make a print statement span several lines without affecting the
final formatting?

I'm sure there was a 'line continuation' character of some sort which we
could insert.

For example, instead of having
print
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbb";

we can have
print "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" LINE CONTINUE CHAR
"bbbbbbbbbbbbbbbbbbbb";

I just want to get my indenting look a bit better.
I can always use 2 print statements instead but do I need to?

Thanks
Voitec
 
I

Iain Chalmers

Voitec said:
Hi,

St00pid question time:

there are no stupid questions, only stupid people ;-)
How can I make a print statement span several lines without affecting the
final formatting?

how about:

print "line 1",
"line 2",
"line 3";

or:

print "line 1".
"line 2".
"line 3";

or perhaps even:

print <<END;
line 1
line 2
line 3
END

big
 
K

ko

Iain said:
[snip]
How can I make a print statement span several lines without affecting the
final formatting?


how about:

print "line 1",
"line 2",
"line 3";

or:

print "line 1".
"line 2".
"line 3";

Those two examples will just concatenate into one long string, not keep
the indenting like the OP wanted - unless you included variables with
indenting/whitespace :) Maybe something like this:

print "
line1
line2
line3
";
or perhaps even:

print <<END;
line 1
line 2
line 3
END

big

Yes :)

To the OP - if you type

perldoc -q "here document"

from your shell, you'll the relevant details of how to correctly use a
'here' document (last example).

HTH - keith
 
A

Andras Malatinszky

Iain said:
there are no stupid questions, only stupid people ;-)




how about:

print "line 1",
"line 2",
"line 3";

or:

print "line 1".
"line 2".
"line 3";

or perhaps even:

print <<END;
line 1
line 2
line 3
END

But this is not equivalent to the previous two! Your third version prints

line1
line2
line3

while the other two print

line1line2line3

(which is apparently what the OP wants).
 
J

James Willmore

How can I make a print statement span several lines without
affecting the final formatting?

perldoc -f format
perldoc perlform

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Acid absorbs 47 times it's weight in excess Reality.
 
G

Gregory Toomey

It was a dark and stormy night, and Voitec managed to scribble:
Hi,

St00pid question time:
How can I make a print statement span several lines without affecting the
final formatting?
The most obvious way us to use "\n" for newline

print "line a\nline b\n\nline c";

Try 'man printf' for a list of other options (C and Perl share some libraries).

gtoomey
 
B

Brad Baxter

It was a dark and stormy night, and Voitec managed to scribble:

The most obvious way us to use "\n" for newline

print "line a\nline b\n\nline c";

Try 'man printf' for a list of other options (C and Perl share some libraries).

gtoomey

Are you sure you didn't misread that questions as:

How can I make the final formatting span several lines without affecting
the print statement?

:)

Regards,

Brad
 
T

the zorg

Iain said:
[snip]
How can I make a print statement span several lines without affecting the
final formatting?


how about:

print "line 1",
"line 2",
"line 3";

or:

print "line 1".
"line 2".
"line 3";

Those two examples will just concatenate into one long string, not keep
the indenting like the OP wanted - unless you included variables with
indenting/whitespace :) Maybe something like this:

No, I believe the first example is what the OP wanted. He wants to
indent the code, not the output.

Thus;

print "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"bbbbbbbbbbbbbbbbbbbbbb";

would indeed seem to do the trick.

Z
 
V

Voitec

*snip*
No, I believe the first example is what the OP wanted. He wants to
indent the code, not the output.

Thus;

print "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"bbbbbbbbbbbbbbbbbbbbbb";

would indeed seem to do the trick.

Z

Thanks. I guess I could have been a little clearer, sorry.
But the intention was to indent the code not the output so the comma
character is exactly what I was looking for.

Thanks to all for the suggestions :c)

Voitec
 
I

Iain Chalmers

Voitec said:
*snip*

Thanks. I guess I could have been a little clearer, sorry.
But the intention was to indent the code not the output so the comma
character is exactly what I was looking for.

Keep in mind that while both the comma and the dot will work, they're
doing slightly different things... The dot is concatenating all the
separate quoted strings together into one big string then printing it,
while the comma is treating each quoted string as a "list item" and
joining them with the current value of $,

see perldoc -f print

big
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top