Re: New Quiz: "What does this code do?" (1-December-2006)
Shlomi Fish <shlomif-ik1l9ssToec+JF/[email protected]> Fri, 15 Dec 2006 10:17:43 +0200
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
On Wednesday 13 December 2006 23:59, Randal L. Schwartz wrote: > >>>>> "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! Actually, this will return the CGI parameters together with the $prefix. I was interested in their names without the prefix. So if I have "toggle1" and "toggle37", I'm interested in "1" and "37" respectively. I've needed them because they were IDs of records in a database table that I needed to do a bulk operation on. Regards, Shlomi Fish --------------------------------------------------------------------- Shlomi Fish shlomif-ik1l9ssToec+JF/[email protected] Homepage: http://www.shlomifish.org/ Chuck Norris wrote a complete Perl 6 implementation in a day but then destroyed all evidence with his bare hands, so no one will know his secrets.