anjiro has asked for the wisdom of the Perl Monks concerning the following question:
I want to replace all occurences of 'FooBarBaz' with something else, say "stuff". However, this doesn't work:my %k; $k{'A'} = 'Foo'; $k{'B'} = 'Bar'; $k{'C'} = 'Baz';
because it interpolates tos/@k{qw(A B C)}/stuff/;
rather thans/Foo Bar Baz/stuff/;
This is particularly irritating becauses/FooBarBaz/stuff;
yields "FooBarBaz". Any thoughts? Yes, I could doprint @k{qw(A B C)}, $/;
But that's so ugly...$x = join('', @k{qw(A B C)}); s/$x/stuff/;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hash slice in regex
by ikegami (Patriarch) on Sep 26, 2006 at 17:21 UTC | |
by anjiro (Beadle) on Sep 26, 2006 at 17:26 UTC | |
|
Re: Hash slice in regex
by hgolden (Pilgrim) on Sep 26, 2006 at 17:26 UTC |