in reply to edge case in substitution?

i actually don't know how to answer your exact question, because i've never used those advanced regex's (something to learn tomorrow!), but it looks like you're just trying to replace all of the sequences behind the names with asterisks, right?
sub obscure { my ( $self, $s ) = @_; use constant REPLACEMENT => '*'; my @pairs = split /&/, $s; my @temp = map { my ( $name, $value ) = split /=/; $name . "=" . REPLACEMENT x length( $value ) } @pairs; return join '&', @temp; }
or without temporary arrays
sub obscure { my ( $self, $s ) = @_; use constant REPLACEMENT => '*'; return join '&', map { my ( $name, $value ) = split /=/; $name . "=" . REPLACEMENT x length( $value ) } split /&/, $s; }

Replies are listed 'Best First'.
Re^2: edge case in substitution?
by graff (Chancellor) on May 18, 2005 at 02:36 UTC
    This is actually a nice approach, especially since it automatically deals with the other edge condition mentioned by ysth below, as well as the one cited in the OP.

    But I think you missed some of the details -- the monk only wants to put in asterisks for certain paramters in the string:

    sub obscure { my ($self, $s) = @_; my %tags = qw/fred x wilbur x/; return join '&', map { my ($n,$v) = split /=/; ( exists( %tags{$n} )) ? "$n=".'*' x length($v) : $_ } split /\&/, $s; }
    (Sorry, but I didn't see the relevance/need for "use constant" there, so I left it out.)

    (updated to fix indentation in the code)