Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Unicode in almost any Browser?!?

by PipTigger (Hermit)
on Jan 14, 2001 at 19:18 UTC ( #51745=CUFP: print w/replies, xml ) Need Help??

Hey fellow Monks... I lerned something cool last week && my cowerker && I were so taken by the discovery that he encouraged me to hack some quick Perl to demonstrate && catalog the ability. The chrz showup in Mozilla && IE (not sure what versions). You can play with it here. Simple but cool AFAIC...
#!/usr/bin/perl -w # a simple Unicode character viewer by =) use strict; use CGI; my $q = new CGI; my $bgin = $q->param("bgin"); unless (defined($bgin)) { $bgin = 12353; + } my $ennd = $q->param("ennd") || 12542; my $rose = $q->param("rose") || 8; #31 my $bord = $q->param("bord"); unless (defined($bord)) { $bord = 1; } +#0 my $padd = $q->param("padd"); unless (defined($padd)) { $padd = 10; } +#0 my $spac = $q->param("spac") || 0; my $hide = $q->param("hide"); #1; my $bcol = $q->param("bcol") || "03072B"; my $tcol = $q->param("tcol") || "A8F8F0"; my $ccol = $q->param("ccol") || "2B1B2B"; my $font = $q->param("font") || qq^font face="Tahoma,Arial,Monaco,Helv +etica,Sans-Serif"^; print "Content-type: text/html\n\n"; my $kaka = $bgin; print qq^<html><head><title>HtmlChrz</title></head>\n^; print qq^<body bgcolor="#$bcol" text="#$tcol"><center>\n^; print qq^<h1><$font>HtmlChrz</font></h1>\n^; print qq^<h3><$font>All following characters are displayed by preceedi +ng the code number with Ampersand-Pound and appending a Semicolon (eg +. &amp;#12353;) within the html source!</font></h3>\n^; print qq^<form method="post"><table border="1"><tr><td><$font>Bgin:</f +ont></td>\n^; print qq^<td><$font><input type="text" name="bgin" value="$bgin"></fon +t></td>\n^; print qq^<td><$font>Ennd:</font></td>\n^; print qq^<td><$font><input type="text" name="ennd" value="$ennd"></fon +t></td></tr>\n^; print qq^<tr><td><$font>Rose:</font></td>\n^; print qq^<td><$font><input type="text" name="rose" value="$rose"></fon +t></td>\n^; print qq^<td><$font>Bord:</font></td>\n^; print qq^<td><$font><input type="text" name="bord" value="$bord"></fon +t></td></tr>\n^; print qq^<tr><td><$font>Padd:</font></td>\n^; print qq^<td><$font><input type="text" name="padd" value="$padd"></fon +t></td>\n^; print qq^<td><$font>Spac:</font></td>\n^; print qq^<td><$font><input type="text" name="spac" value="$spac"></fon +t></td></tr>\n^; print qq^<tr><td><$font>BCol:</font></td>\n^; print qq^<td><$font><input type="text" name="bcol" value="$bcol"></fon +t></td>\n^; print qq^<td><$font>TCol:</font></td>\n^; print qq^<td><$font><input type="text" name="tcol" value="$tcol"></fon +t></td></tr>\n^; print qq^<tr><td><$font>CCol:</font></td>\n^; print qq^<td><$font><input type="text" name="ccol" value="$ccol"></fon +t></td>\n^; print qq^<td><$font>Hide:</font></td>\n^; print qq^<td><$font><input type="checkbox" name="hide" value="1"^; if ($hide) { print " checked"; } print qq^></td></tr>\n^; $font =~ s/\"/\&quot;/g; print qq^<tr><td colspan="4" align="center"><input type="text" name="f +ont" value="$font" size="63"></td></tr>\n^; print qq^<tr><td colspan="4" align="center"><input type="submit" name= +"submit" value="ShowChrz"></td></tr>\n^; print qq^</table></form><hr><br>\n^; print qq^<table border="$bord" cellpadding="$padd" cellspacing="$spac" +>\n^; while ($kaka < $ennd) { my $poop = $kaka + $rose; print qq^<tr>^; while ($kaka < $poop) { print qq^<td bgcolor="$ccol"><$font>^; unless ($hide) { print qq^<b>$kaka</b>: ^; } print qq^&#$kaka;&nbsp;</font></td>\n^; $kaka++; } print qq^</tr>^; $kaka++; } print qq^</table></body></html>\n^;


p.s. Initiate Nail Removal Immediately!

Replies are listed 'Best First'.
Re: Unicode in almost any Browser?!?
by OeufMayo (Curate) on Jan 14, 2001 at 20:25 UTC

    Perhaps you should change those nasty lines of

    and make your code easier to read/maintain by either using "here documents" like this:

    print <<"END_OF_HTML"; # double-quotes allows interpolation <html> ... </html> END_OF_HTML

    or, better, using features to produce the HTML code for you:

    use CGI qw(:standard); print header, h1($some_title), hr; # etc...

    You can also use templates modules (HTML-Template, Template-Toolkit,...) to separate your code from your layout

    PerlMonger::Paris(http => '');</kbd>
Re: Unicode in almost any Browser?!?
by chromatic (Archbishop) on Jan 17, 2001 at 10:25 UTC
    Is there any particular reason (bug workaround, stylistic evolution, personal preference, difference in functionality of which I'm not aware) some of the param accesses use the logical or operator and others use a defined check?

    I prefer the form:

    my $bcol = $q->param("bcol") || "03072B";

    It is concise and easy to read. Consistency is very important, especially when debugging.

      I thinq I did it that way because I wanted the form to accept "0" for the border width && cell padding but not for any of the other fields. If the form is submitted with a "0" in the fields seeded w/ "|| xxxx", it'll get the default value but I used the "unless defined" construct in order to avoid overriding a valid "0" value from the form. I'm sure I'm describing this way too verbosely here. I hope it makes sense.

      There's surely a better way I'm not aware of to handle these conditions in the code too. I really should've used the "here document" method for printing all that stuff to. Thanks for the suggestion OeufMayo! I'll try to remember that next time =). Shalom.

        I'll try to remember that next time =).
        yeah, right. ;-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://51745]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2017-02-19 14:53 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (292 votes). Check out past polls.