print statement spanning multiple lines

Discussion in 'Perl Misc' started by Voitec, Nov 11, 2003.

  1. Voitec

    Voitec Guest

    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
     
    Voitec, Nov 11, 2003
    #1
    1. Advertising

  2. In article <ceXrb.6024$>,
    "Voitec" <> 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
     
    Iain Chalmers, Nov 11, 2003
    #2
    1. Advertising

  3. Voitec

    ko Guest

    Iain Chalmers wrote:
    > In article <ceXrb.6024$>,
    > "Voitec" <> 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
     
    ko, Nov 11, 2003
    #3
  4. Iain Chalmers wrote:
    > In article <ceXrb.6024$>,
    > "Voitec" <> 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).
     
    Andras Malatinszky, Nov 11, 2003
    #4
  5. On Tue, 11 Nov 2003 01:48:56 GMT
    "Voitec" <> 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.
     
    James Willmore, Nov 11, 2003
    #5
  6. 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
     
    Gregory Toomey, Nov 11, 2003
    #6
  7. Voitec

    Brad Baxter Guest

    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
     
    Brad Baxter, Nov 11, 2003
    #7
  8. Voitec

    the zorg Guest

    On Tue, 11 Nov 2003 12:02:26 +0900, ko <> wrote:

    >Iain Chalmers wrote:
    >> In article <ceXrb.6024$>,
    >> "Voitec" <> 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
    >
     
    the zorg, Nov 11, 2003
    #8
  9. Voitec

    Voitec Guest

    *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
     
    Voitec, Nov 12, 2003
    #9
  10. In article <FEisb.7553$>,
    "Voitec" <> 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
     
    Iain Chalmers, Nov 13, 2003
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sriram Rajagopalan

    Syntax for variable names spanning multiple lines in C

    Sriram Rajagopalan, Nov 13, 2006, in forum: C Programming
    Replies:
    28
    Views:
    855
    Richard Bos
    Nov 16, 2006
  2. pbd22
    Replies:
    0
    Views:
    298
    pbd22
    Nov 18, 2007
  3. Mark
    Replies:
    4
    Views:
    1,234
    Hermann Peifer
    Mar 27, 2009
  4. Jamie Jackson

    Spanning Lines & Dynamic Pattern Matching

    Jamie Jackson, Oct 25, 2004, in forum: Javascript
    Replies:
    5
    Views:
    115
    Jamie Jackson
    Oct 26, 2004
  5. animesh
    Replies:
    0
    Views:
    86
    animesh
    Dec 10, 2007
Loading...

Share This Page