Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: Printing From a File Handle

by bkiahg (Pilgrim)
on Apr 28, 2004 at 20:27 UTC ( [id://348938]=note: print w/replies, xml ) Need Help??


in reply to Re: Printing From a File Handle
in thread Printing From a File Handle

Is there anyway to add html formatting to it? e.g.
print while "<AP_MENU><br>";

Replies are listed 'Best First'.
Re: Re: Re: Printing From a File Handle
by haoess (Curate) on Apr 28, 2004 at 20:36 UTC
    TIMTOWTDI:
    # shortest print "$_<br />" while <AP_MENU>; # show what you mean { local $\ = "<br />"; print while <AP_MENU>; } # more readable? foreach my $line (<FILE>) { print $line, "<br />"; }
    -- Frank
Re^3: Printing From a File Handle
by tkil (Monk) on Apr 29, 2004 at 02:04 UTC

    Still more ways to do it:

    # list processing print map "$_<br />", <AP_MENU>; # more abuse of special variables { local $, = "<br />"; print <AP_MENU>, ''; }

    If you are reading in any old file for display in an HTML page, you will want to do at least minimal escaping of special characters, too:

    while ( <AP_MENU> ) { # protect against most egregious HTML violations s/&/&amp;/g; s/</&lt;/g; s/>/&gt;/g; # remove trailing whitespace so the <br /> is on # the same line as main text s/\s+$//; print "$_<br />\n"; }
      Good call tkil I forgot about escaping html characters!
Re: Re: Re: Printing From a File Handle
by Elijah (Hermit) on Apr 28, 2004 at 21:14 UTC
    #!/usr/bin/perl print "Content-type: text/html\n\n"; print <<top; <html> <head><title>Some Title</title></head> <body bgcolor="#000000"> top print "<font color=\"#FFFFFF\">$_</font><br>" for <DATA>; print <<bottom; </body> </html> bottom __DATA__ Test Test Again One More Test!
    You can see it work here.

    www.perlskripts.com

Log In?
Username:
Password:

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

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

    No recent polls found