Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   print statement spanning multiple lines (http://www.velocityreviews.com/forums/t883569-print-statement-spanning-multiple-lines.html)

Voitec 11-11-2003 01:48 AM

print statement spanning multiple lines
 
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
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbb bbbbbbbbbbb";

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



Iain Chalmers 11-11-2003 02:11 AM

Re: print statement spanning multiple lines
 
In article <ceXrb.6024$aT.23@news-server.bigpond.net.au>,
"Voitec" <voitec@zzzzzzzzz.com> wrote:

> 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

--
'When I first met Katho, she had a meat cleaver in one hand and
half a sheep in the other. "Come in", she says, "Hammo's not here.
I hope you like meat.' Sharkey in aus.moto

ko 11-11-2003 03:02 AM

Re: print statement spanning multiple lines
 
Iain Chalmers wrote:
> In article <ceXrb.6024$aT.23@news-server.bigpond.net.au>,
> "Voitec" <voitec@zzzzzzzzz.com> wrote:


[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


Andras Malatinszky 11-11-2003 03:13 AM

Re: print statement spanning multiple lines
 


Iain Chalmers wrote:
> In article <ceXrb.6024$aT.23@news-server.bigpond.net.au>,
> "Voitec" <voitec@zzzzzzzzz.com> wrote:
>
>
>>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


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).


James Willmore 11-11-2003 05:21 AM

Re: print statement spanning multiple lines
 
On Tue, 11 Nov 2003 01:48:56 GMT
"Voitec" <voitec@zzzzzzzzz.com> wrote:
> 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.


Gregory Toomey 11-11-2003 05:35 AM

Re: print statement spanning multiple lines
 
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

Brad Baxter 11-11-2003 02:50 PM

Re: print statement spanning multiple lines
 
On Tue, 11 Nov 2003, Gregory Toomey wrote:

> 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
>


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

the zorg 11-11-2003 07:51 PM

Re: print statement spanning multiple lines
 
On Tue, 11 Nov 2003 12:02:26 +0900, ko <kuujinbo@hotmail.com> wrote:

>Iain Chalmers wrote:
>> In article <ceXrb.6024$aT.23@news-server.bigpond.net.au>,
>> "Voitec" <voitec@zzzzzzzzz.com> wrote:

>
>[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


>
>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
>



Voitec 11-12-2003 04:27 AM

Re: print statement spanning multiple lines
 
*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



Iain Chalmers 11-13-2003 02:03 AM

Re: print statement spanning multiple lines
 
In article <FEisb.7553$aT.2479@news-server.bigpond.net.au>,
"Voitec" <voitec@zzzzzzzzz.com> wrote:

> *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.


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

--
'When I first met Katho, she had a meat cleaver in one hand and
half a sheep in the other. "Come in", she says, "Hammo's not here.
I hope you like meat.' Sharkey in aus.moto


All times are GMT. The time now is 08:48 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57