Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: I can't make a new line =(

by monkfan (Curate)
on Jun 13, 2006 at 06:07 UTC ( [id://554961]=note: print w/replies, xml ) Need Help??


in reply to I can't make a new line =(

It's very hard to figure out what you intend to do.
Basicallly ("\n") stands for a newline so whenever you include it, it will break the line? Perhaps what you want is "concatenation".
If so you can do it this way:
my @lines = qw (foo bar qux); my $final_line = ""; foreach $line(@lines) { $final_line .= $line." "; } print "$final_line\n"; #include linebreak (\n) here
gives you:
foo bar qux #newline here
or is there any particular thing other than that?
Can you give us your sample script?

Regards,
Edward

Replies are listed 'Best First'.
Re^2: I can't make a new line =(
by frederick213 (Initiate) on Jun 13, 2006 at 06:37 UTC

    yea, i want to break the line into a new one... this is my script. i don't know how to minimize the font, so i just put a comment between the two statements i want to separate.

    #!C:\Perl\bin\perl.exe -wT use strict; use CGI ':standard'; my ($number,$value); $number = param('number'); $value = param('name'); print "Content-type:text/html\n\n"; $number = $number + 20; print "$value will be $number in twenty years."; # separate above operation from below condition if ($number >= 40) { print "Wow $value, you're old!"; } else { print "Wow $value, you're still young!"; }

    davorg: added code tags

      Please update your reply by putting <code> and </code> around your perl snippet, so we can read that part correctly as perl code.

      You are printing html output to a browser; the browser is supposed to treat all white-space characters the same (newlines are no different from spaces or tabs or carriage returns).

      To tell the browser to break a line, include a "<br>" tag (or, to be more XML-ish, "<br/>") at the point where you would normally use "\n".

      Update: to be more precise, something like this would do:

      my $quality = ( $number >= 40 ) ? "old" : "still young"; print "$value will be $number in twenty years.<br>Wow $value, you're $ +quality!";
      Just use br tag, see the script below.
      #!C:\Perl\bin\perl.exe -wT use strict; use CGI ':standard'; my ($number,$value); $number = param('number'); $value = param('name'); print "Content-type:text/html",br,br; $number = $number + 20; print "$value will be $number in twenty years."; # separate above operation from below condition print br,br; #<------------- Use br if ($number >= 40) { print "Wow $value, you're old!"; } else { print "Wow $value, you're still young!"; }

      Regards,
      Edward

      Ok, now I've added code tags, I can see what you're doing and can make another suggestion.

      you're telling the browser that your output is HTML (in the content type header). But actually, you're not sending HTML, you're sending plain text. If you tell the browser that you're sending plain text, then it will treat your output as plain text and honour your newlines.

      The simplest way to do that is to change your content type header:

      print "Content-type:text/plain\n\n";

      But as you're using CGI.pm, why not use the header function to make your life easier:

      print header(-type => 'text/plain');
      --
      <http://dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

      sorry, just saw how piled up that looks... i don't know how to make it look like the post you just made

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://554961]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-23 07:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found