Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical


by blue_cowdawg (Monsignor)
on Oct 19, 2012 at 15:53 UTC ( #999960=note: print w/replies, xml ) Need Help??

in reply to PERL HTML HELP

Really this is less of a Perl question and more of an HTML question, but I'll bite.

My favorite way to render HTML pages is using HTML::Template which allows me to create a set of template files with "placeholders" that I use later to populate real data into the rendered page. I won't go into a whole tutorial on that here, but that's one thing to look at.

My second favorite is to use the CGI module. Example:

#!/usr/bin/perl -w use strict; use CGI qw/:all/; print start_html,p("Hello world"),end_html;
which produces:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns="" lang="en-US" xml:lang="en-U +S"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> <p>Hello world</p> </body> </html>
If your trying to output to a file instead of STDOUT you'd do something like this:
#!/usr/bin/perl -w use strict; use CGI qw/:all/; open FOUT,"> my_html_page.html" or die $!; print FOUT start_html,p("Hello world"),end_html;

As far as each letter having a different color goes I'm not sure what you are after but if I want to change the color of some text it's going to look something like:

#!/usr/bin/perl -w use strict; use CGI qw/:all/; print start_html,p({ style => "color: red;"},"Hello world"),end_html;
and if you're using a CSS sheet and have a class or id set up for what you want you can invoke it with {id => "foo"} just as I did with the style invocation above.

As far as keeping your columns even and forcing a wraparound within a cell goes, that is strictly and HTML issue. Here (from a Perl perspective) what that looks like:

print table({width=>'80%',tr(td({width=>'30%',"thing1"), td({width=>'60%',"thing2"), td({width=>'10%',"a really long thing") ));
The very right most column being the smallest and depending on the screen size should wrap nicely.

There are other subtleties to explore in a combination of Perl-fu and HTML-fu and are beyond the scope of this thread.

Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Replies are listed 'Best First'.
by Singh121 (Initiate) on Oct 20, 2012 at 11:01 UTC
    ah great info thank you, its funny the code seems so basic and logical but as a newbie i guess it takes a little time to grasp, but thank you very much for your help :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999960]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2017-01-18 21:26 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (164 votes). Check out past polls.