Click the box titles below to expand:
How to's
XSLT
GOOGLE MAPS API
PHP
- PHP & Web Services — using SOAP to get meteorological data for a location
- PHP and Flickr accessing online photos through the phpFlickr class
Antelope
- Github, Git & contrib
- Antelope & Using amakelocal
- Antelope & Matlab time conversion
- Create an Antelope Mail Archive
- Adding new projects to the Antelope contrib area using CVS
Perl
Document Object Model (DOM)
UNIX
- Convert GE KML files for use with GMT
- Various snippets that make my life easier
- Using Subversion to version control web sites
Generic Mapping Tools (GMT)
Miscellaneous
Projects
Courses Taught
Latest Favorites
- Best of Vim tips
- Make your pages load faster by combining and compressing javascript and css files
- Creating Liquid Faux Columns
- Setting up SSL under Apache 2 on SuSE
- PHP editing with ViM
- Getting equal-height columns in a three-column layout
- Star html Selector Bug
- Reset MySQL root account permissions
- How to write UNIX man pages
- Son of Suckerfish Dropdowns
- Aidan's PHP Repository
- Adium IM client
- ShapeShifter
- Install wiki on an iBook
- Quirksmode
- PHP
- GD
- JpGraph
- Vim Text Editor
- Generic Mapping Tools (GMT)
Mac OS X
Web Development
Beta
How To :: Perl :: Dealing with hashes in Perl
Recently I had to process an old online form. In the form there is a hash called %FORM that contains all the form submission data. The site admins wanted the ability to add multiple select options and the Perl script to parse that information.
So we have multiple selects named account_type and list with multiple values. Here is how to process it:
#!/path/to/perl ..... my $buffer ; my %FORM; foreach my $pair (@pairs) { my( $name, $value ) ; ..... if( $name eq 'account_type' ) { } elsif( eq 'list' ) { } else { $FORM{$name} = $value ; } }
We use the values from account_type to determine what the subject line in a confirmation email is (among other things). Several options equate to this same thing (such as if you want a building account, backup account then these both are Mac accounts). To make sure that we don't get duplications in the subject line we do:
..... my @type_list ; my %seen = () ; # record what we have seen foreach my $subj_act_type (@{$FORM{"account_type"}} ) { if( $subj_act_type eq "igpphome" || $subj_act_type eq "trident" || $subj_act_type eq "popmail" ) { unless( $seen{"Mac"} ) { # check if exists $seen{"Mac"} = 1 ; } } if( $subj_act_type eq "sun" ) { } } print MAIL "Subject: $joined_type_list New User Account Application\n\n";
The check to see if the array value exists is from the O'Reilly Perl Cookbook (4.6).
The interesting thing to notice is the foreach() part. The same goes for applying to listserves from this form:
foreach my $mylist (@{$FORM{"list"}} ) { }
These three code snippets show an interesting way of casting Perl variables, arrays and hashes.
The notation in the foreach() loop looks ugly, but it works well. Bascially you have to dereference the hash and recast it as a scalar, then recast that as an array. Yuck.
More information:
Credits: Thanks to Edgar Milik for showing me all this Perl malarky.