GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  TIE::REGEXPHASH (3)

.ds Aq ’

NAME

Tie::RegexpHash - Use regular expressions as hash keys

CONTENTS

SYNOPSIS



  use Tie::RegexpHash;

  my %hash;

  tie %hash, Tie::RegexpHash;

  $hash{ qr/^5(\s+|-)?gal(\.|lons?)?/i } = 5-GAL;

  $hash{5 gal};     # returns "5-GAL"
  $hash{5GAL};      # returns "5-GAL"
  $hash{5  gallon}; # also returns "5-GAL"

  my $rehash = Tie::RegexpHash->new();

  $rehash->add( qr/\d+(\.\d+)?/, "contains a number" );
  $rehash->add( qr/s$/,          "ends with an \`s\" );

  $rehash->match( "foo 123" );  # returns "contains a number"
  $rehash->match( "examples" ); # returns "ends with an `s"



DESCRIPTION

This module allows one to use regular expressions for hash keys, so that values can be associated with anything that matches the key.

Hashes can be operated on using the standard tied hash interface in Perl, or using an object-oriented interface described below.

    Methods

new


  my $obj = Tie::RegexpHash->new()



Creates a new RegexpHash (Regular Expression Hash) object.

add


  $obj->add( $key, $value );



Adds a new key/value pair to the hash. $key can be a Regexp or a string (which is compiled into a Regexp).

If $key is already defined, the value will be changed. If $key matches an existing key (but is not the same), a warning will be shown if warnings are enabled.

match


  $value = $obj->match( $quasikey );



Returns the value associated with $quasikey. ($quasikey can be a string which matches an existing Regexp or an actual Regexp.) Returns ’undef’ if there is no match.

Regexps are matched in the order they are defined.

match_exists


  if ($obj->match_exists( $quasikey )) ...



Returns a true value if there exists a matching key.

remove


  $value = $obj->remove( $quasikey );



Deletes the key associated with $quasikey. If $quasikey matches an existing key (but is not the same), a warning will be shown.

Returns the value associated with the key.

clear


  $obj->clear();



Removes all key/value pairs.

AUTHOR

Robert Rothenberg <rrwo at cpan.org>

    Acknowledgments

Russell Harrison <rch at cpan.org> for patches adding support for serialization.

Simon Hanmer <sch at scubaplus.co.uk> & Bart Vetters <robartes at nirya.eb> for pointing out a bug in the logic of the _find() routine in v0.10

LICENSE

Copyright (c) 2001-2002, 2005-2006 Robert Rothenberg. All rights reserved.

Portions Copyright (c) 2006 Russell Harrison. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Tie::Hash::Regex is a module with a complimentary function. Rather than a hash with Regexps as keys that match against fetches, it has standard keys that are matched by Regexps in fetches.

Regexp::Match::Any matches many Regexps against a variable.

Regexp::Match::List is similar, but supports callbacks and various optimizations.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 TIE::REGEXPHASH (3) 2014-02-02

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.