Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The following code catches all cases except for the last.my $string = 'fred=abcdef&wilbur=123456&fred=hijk';
How do I write the second substitution to catch the end-of-line case? Thanks.sub obscure { my ($self, $s) = @_; use constant REPLACEMENT => '*'; my @tags = qw/fred wilbur/; for my $tag (@tags) { $s =~ s{$tag=(.*?)\&}{ "$tag=" . (REPLACEMENT x length($1)) . '&' }gex; $s =~ s/$tag=(.*)$/"$tag="/gex; # WRONG } return $s; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: edge case in substitution?
by Roy Johnson (Monsignor) on May 17, 2005 at 23:06 UTC | |
|
Re: edge case in substitution?
by ysth (Canon) on May 17, 2005 at 23:53 UTC | |
|
Re: edge case in substitution?
by mrborisguy (Hermit) on May 17, 2005 at 23:08 UTC | |
by graff (Chancellor) on May 18, 2005 at 02:36 UTC | |
|
Re: edge case in substitution?
by Anonymous Monk on May 18, 2005 at 03:39 UTC |