in reply to Simplifying the following code
my %params = $cgi->Vars; # Now Kanji's code becomes foreach my $file ( qw (file1 file2 file3 ...) ) { push @tour_photos, $params{$file} if exists($params{$file}) && $params{$file} ne ''; }
Update: Took the incorrect commas out of the qw(), *sigh* posting on weekends again... and changed 'defined' to 'exists' since it is now in a hash.
Since it came up in chatterbox, I'd like to point out that CGI will take a multiple items with the same form 'name' and cram them into an array. Fastolfe demonstrated that in another post here. I should warn you that if the various "fileXX" files have specific purposes then that method may not be for you. Order from the client isn't guaranteed to be the same as the order in the HTML form. I can't recall a browser that fails to do so off the top of my head but that fact is out there, waiting to bite the overconfident. Like, for instance, me. =)
Up-Update Kanji kindly points out that the Vars method of CGI happens to act like cgi-lib.pl and it puts multiple items into a single string separated by friggin' nulls "\00" so while the above is correct in warning you about disordered items, it is miserably wrong about how Vars treats your lists. =) Now, I'm going to crawl under a rock, thank you and good night.
--
$you = new YOU;
honk() if $you->love(perl)
|
|---|