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

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

Replies are listed 'Best First'.
Re^3: I can't make a new line =(
by graff (Chancellor) on Jun 13, 2006 at 06:44 UTC
    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!";
Re^3: I can't make a new line =(
by monkfan (Curate) on Jun 13, 2006 at 06:47 UTC
    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
Re^3: I can't make a new line =(
by davorg (Chancellor) on Jun 13, 2006 at 08:57 UTC

    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

Re^3: I can't make a new line =(
by frederick213 (Initiate) on Jun 13, 2006 at 06:47 UTC
    sorry, just saw how piled up that looks... i don't know how to make it look like the post you just made