ServersThe Perl Basics You Need To Know Page 6

The Perl Basics You Need To Know Page 6

ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.




  #####################################################
  # Build_MatchMany_Function
  # -- Input:  list of patterns
  # -- Output: A code ref which matches its sh[0]
  #            against ANY of the patterns given in the
  #            "Input", efficiently.
  #
  sub Build_MatchMany_Function {
    my @R = @_;
    my  = join '||', map { "$_[0] =~ m/$R[sh]/o" } ( 0..0R );
    my  = eval "sub {  }";
    die "Failed in building regex @R: " if ;
    ;
  }

Example usage:

  @some_browsers = qw(Mozilla Lynx MSIE AmigaVoyager lwp libwww);
  =Build_MatchMany_Function(@some_browsers);
  
  while () {
    # ...
     = get_browser_field(sh);
    if ( ! &() ) {
      print STDERR "Unknown Browser: n";
    }
    # ...
  }

In the next article I'll present a few other Perl basics directly related
to the mod_perl programming.

References

  • The book Mastering Regular Expressions by Jeffery Friedl.

  • The book Programming Perl by L.Wall, T. Christiansen and
    J.Orwant (also known as the Camel book, named after the camel picture
    on the cover of the book).

  • The Exporter, perlre, perlvar,
    perlmod and perlmodlib man pages.

About the Author

Stas Bekman is an author of
the mod_perl Guide and
is currently co-athoring a book about mod_perl for
O’Reilly and Associates, Inc
together with
Eric Cholet.
He is a member of the
Apache Software Foundation.
You can find more about his works and joys at his
personal Web site.

Get the Free Newsletter!

Subscribe to Daily Tech Insider for top news, trends & analysis

Latest Posts

Related Stories