photo
Jordan Sissel
geek

Tue, 23 Dec 2003

PHP -> perl HTML::Mason

I'm going to have a go learning HTML::Mason and in the process of doing so will convert this entire site to mason. I'll be posting updates and neat things I learn here, stay tuned...

Comments: 0 (view comments)
Tags: ,
Permalink: /geekery/89
posted at: 23:13

perl's CGI module

I have overlooked some of the coolest parts of perl's CGI module for the longest time - I've known it can generate HTML but I've always shrugged it off as thinking it can't do what i want it to, i couldn't have been more wrong.

What I'm specifically referring to is form generation. The rest of the HTML generating methods are useless to me (like the h1() method), but I'll focus on the cool form generating ones.
Why are they cool? They simplify your life and make code cleaner - For instance, lets say oyu have this fugly line of code:

$poop = "email_address";
$default = "user@somedomain.com"
print 'Email address: <input type="text" name="' . $poop .  
      '" value="' . $default . '"><br>';

This prints out happy html that looks like this:
Email address:

Now, that print line is pretty damn ugly, but we can easily make it pretty once more by doing:
use CGI qw/:standard/;
print "Email Address: " . textfield($poop, $default) . "<br>";

And the output is:
Email Address:

Neat? Yeah.. What next? More neatness! You have an array you want to turn into a group of checkboxes...

use CGI qw/:standard/;
@foo = ("check1", "foo", "bar", "baz", "poopie", "hello", "Coke!", "Pepsi?");
@def = ("foo", "bar", "poopie");
print 'Checkbox listing:<br>';
print checkbox_group(-name => "options", -values => \@foo, 
                     -columns => 3, -defaults => \@def);
print '<br>';
What does this look like?

Checkbox listing:
check1bazCoke!
foopoopiePepsi?
barhello

Comments: 0 (view comments)
Tags:
Permalink: /geekery/88
posted at: 20:14

Search this site

Navigation

Metadata

Home About Resume My Code (SVN)

Articles

ARP Security Dynamic DNS with DHCP OpenLDAP+Kerberos+SASL PPP over SSH SSH Security: /bin/false Week of Unix Tools Work Efficiency

Projects

fex firefox tabsearch firefox urledit grok keynav liboverride newpsm (FreeBSD) nis2ldap pam_captcha poor man's backup Solaris audio utility xboxproxy xdotool xmlpresenter xpathtool misc scripts

Presentations

Yahoo! Hack Day '06 Unix Essentials Vi/Vim Essentials

Tag Cloud

Calendar

< December 2003 >
SuMoTuWeThFrSa
  1 2 3 4 5 6
7 8 910111213
14151617181920
21222324252627
28293031   

Friends

BarCamp Kent Brewster Tantek Çelik John Resig Wesley Shields Tyler Shields

Technorati