On Sat, Jan 25, 2014 at 03:51:53PM +0100, Luca Ferrari wrote:
> Hi,
> I'm just wondering if it is possible to place a regexp as a value into
> an hash so to use it later as something like:
> 
> my $string =~ $hash_ref->{ $key };
> 
> Is it possible? Should I take into account something special?

Yes, this is possible.  You need to use qr// to construct your RE:

$ perl -E '$h = { a => qr/y/ }; say $_ =~ $h->{a} for qw(x y z)'

1

$

-- 
Paul Johnson - p...@pjcj.net
http://www.pjcj.net

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to