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

hi,

Just wondering how i can search paremeter names? so if i had a form with input values with the names of "hello1", "hello2", "hello345". now the numbers after the word "hello" may be different depending on the end user, so i need a way to retreive all input values with the paremeter name having "hello" inside of it. does that require some sort of regex?

btw, I am using CGI.pm to parse form values.

Thanks,
bobby

Replies are listed 'Best First'.
Re: searching parameter names
by reasonablekeith (Deacon) on Mar 24, 2006 at 12:18 UTC
    You just need to search through all the parameter names looking for the ones which match you condition. If you're using CGI, you can do something like this.
    my $q = new CGI; my @hello_param_names = grep {m/hello/} $q->param();
    ---
    my name's not Keith, and I'm not reasonable.
      Thank you,

      works great. So to actually retreive the values, I would have to do a little foreach statement and then print the values. Is there a shorter way I can take this concept but instead of storing the names of the paremeters, just store the actual values of all paremeters with the world "hello". That way, I would have one less foreach statement in my code. I'll continue trying to figure it out and if I do, I'll repost it here for future ref.
        You mean like this?
        my @hello_values = map { $q->param($_) } grep {m/hello/} $q->param(); # untested!
        ---
        my name's not Keith, and I'm not reasonable.
Re: searching parameter names
by gube (Parson) on Mar 24, 2006 at 12:30 UTC

    Hi try this,

    #!/usr/local/bin/perl use CGI; my $q = new CGI; my $search_word = $q->param('search_word'); my @parameters = qw(hello1 hello2 hello345 gube); @values = grep /^$search_word\d+/, @parameters; print "@values";

    Always, mention the input clearly and ask the clear output in what output you need. And paste, the code what you have tried before and where you are struggle...