#--- complex.pm package complex; use strict; sub whatis{ my $self = shift; my $input = shift; my %data = ( ip_address => \qr/\d+\.\d+\.\d+\.\d+/, phone => \qr/^\d{3}[-]\d{3}[-]\d{4}$/, ); foreach(keys %data){ return $data{$_} if /$input/; } return 0; } 1; #--- test.pl #!/perl/bin/perl use complex; use strict; my @list1 = qw ( 704-123-4569 115.43.2.123 112.32.24.2 ); push @list1, "312-231-2312 (ext. 23)"; my @list2 = qw ( ip_address phone ); foreach (@list1){ foreach my $x (@list2){ if ( /${complex->whatis($x)}/ ){ print "$_ is an $x\n"; } } if ( /${complex->whatis('phone')}*\s+\(ext\. (\d+)\)/ ){ print "$_ is an phone with ext $1 \n"; } }
Don't know if this helps... return a ref to your objects variable? then de-ref it in your regex and append any additonal expressions? (In this example, I use qr to in the hash, and pass a ref back... I think I can see why you would do this... interesting..)

James :)

In reply to Re: Regexp and object's methods. by JamesNC
in thread Regexp and object's methods. by nite_man

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.