Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Ignore case of query string parameter

by lpoht (Sexton)
on Jun 12, 2002 at 18:46 UTC ( [id://173956]=perlquestion: print w/replies, xml ) Need Help??

lpoht has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm new to perl, but can't seem to find an answer to my problem. I have a piece of code which grabs HTTP query string variables as such:
$pageid=$query->param('pageid');
where $query is the query string. I want to be able to ignore the case of the names of the parameters (i.e. accept "PageID", "PagEiD", etc.) without grabbing the whole query string (with the ENV variable), then splitting it, searching it, etc. Any ideas? Thanks.

Replies are listed 'Best First'.
Re: Ignore case of query string parameter
by George_Sherston (Vicar) on Jun 12, 2002 at 18:55 UTC
    Other monks may have a specific way to do what you want, but you might also find it useful that CGI.pm (I think I'm right in guessing you are using this?) offers: @array_of_submitted_parameter_names = $query->param; So you could get them all and then loop through them picking up the ones that meet your needs, e.g. in the case you're looking at:
    my @ary = $query->param; my $pageid; for (@ary) { if (lc $_ eq 'pageid') { $pageid = $query->param($_); } }


    § George Sherston
Re: Ignore case of query string parameter
by c-era (Curate) on Jun 12, 2002 at 18:59 UTC
    I haven't tested this code, but it should work ;)
    my %params; for my $paramName ($query->param){ $params{lc($paramName)} = $query->param($paramName); }
    All of your params should be in the %params hash, and you just use the lc version of your param name to access your value.
      same untested code but written into one line :)
      my %params = map {(lc($_)=>$query->param($_))} $query->param;
      (personally I tend to write similar code this way)

      Best wishes
      Weasel

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://173956]
Approved by VSarkiss
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-25 19:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found