slugger415 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, this might be a dumb question, but I'm still learning.
I'm doing a series of string substitutions in a file. I have a hash, something like this:
my %subs = ( "Xaa1" => "sub1", "Xaa11" => "sub2", ); foreach my $s (keys %subs){ $data =~ s/$s/$subs{$s}/g; }
I'm sure you can see the problem here. If the string is "Xaa11" it might first substitute "Xaa1" and never see the final "1", so the result ends up being "sub11" instead of "sub2".
Am I going about this the right way, and how to I make sure it checks to the end of "Xaa11"?
Thank you!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: regex/substitution question
by ikegami (Patriarch) on Feb 07, 2012 at 18:41 UTC | |
by slugger415 (Monk) on Feb 07, 2012 at 19:32 UTC | |
by ikegami (Patriarch) on Feb 07, 2012 at 21:43 UTC | |
Re: regex/substitution question
by AnomalousMonk (Archbishop) on Feb 07, 2012 at 23:47 UTC | |
by slugger415 (Monk) on Feb 09, 2012 at 16:34 UTC |
Back to
Seekers of Perl Wisdom