The Perl Basics You Need To Know Page 6 | ServerWatch

The Perl Basics You Need To Know Page 6

Written By
Stas Bekman
Stas Bekman
Jul 20, 2010
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.
Stas Bekman

Stas Bekman is a ServerWatch contributor.

ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.