Re: New Quiz: "What does this code do?" (1-December-2006)

[email protected] (Randal L. Schwartz) 13 Dec 2006 13:59:29 -0800
Newsgroups gmane.comp.lang.perl.qotw.discuss
Message-ID <[email protected]>
>>>>> "Owen" == Owen  <rcook-iMDvLBO0GCq6c6uEtOJ/[email protected]> writes:

>> my (@list) =
>> (
>> grep { $cgi->param("$prefix$_") }
>> map { /^${prefix}(\d+)$/ ? ($1) : () }
>> $cgi->param()
>> );

Owen> I have waited 60 hours and more now. Just wondering if there was a
Owen> follow up to the message because like the friend above, I too have
Owen> problems understanding what was going on!

Given a $prefix like "addressline", @list will contain a list of all numbers
tailed from elements like "addressline1" and "addressline37" that contain
non-false form values (1 and 37 in this case).

I don't think that'd be as useful as hand coding this instead:

my @addressline = grep { /^addressline/ and defined param($_) } param();

That's how I'd do that instead.  To use them, you're gonna need to go
back to the full $prefix form anyway!

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[email protected]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!