On Sat, Jan 25, 2014 at 06:41:00PM +0100, Luca Ferrari wrote: > On Sat, Jan 25, 2014 at 4:12 PM, Paul Johnson <p...@pjcj.net> wrote: > > > $ perl -E '$h = { a => qr/y/ }; say $_ =~ $h->{a} for qw(x y z)' > > Thanks, but then another doubt: having a look at > http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators I dont > understand how I can use the regexp for substitution, that is s/// as > an hash value. The following is not working: > my $hash = { q/regexp/ => qr/s,from,to,/ };
You won't be able to do the full substitution this way, but you can use the RE in the substitution: $ perl -E '$h = { a => qr/y/ }; say $_ =~ s/$h->{a}/p/r for qw(x y z)' x p z $ If the replacement text is different for each substitution then you may be better served storing anonymous subs in your hash: $ perl -E '$h = { a => sub { s/y/p/r } }; say $h->{a}->() for qw(x y z)' x p z $ Good luck. -- 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/