[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Grep based on user input?



mfischer@fishmancom.com (Matthew Fischer) wrote:
>How can you dynamically build a grep pattern based on user input from a form?
>
>i.e.: (I know this doesn't work):
>
>  if ($input{'month'} ne "") {
>      @allfiles = grep(/$input{'month'}/,@allfiles); 
>      }

What doesn't work about it?  It should work.  But you probably want to
be much more careful about opening up your site to attack from malicious
regexps.  Something like:

  if ($input{'month'} ne "") {
      @allfiles = grep(/\Q$input{'month'}/,@allfiles); 
  }


  -------------------                            -------------------
  Ken Williams                             Last Bastion of Euclidity
  ken@forum.swarthmore.edu                            The Math Forum

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org