in reply to Re: howto replace part of a string
in thread howto replace part of a string

Well, for starters, you're using 5, 4, and *, rather than 10 and 20. Secondly, you're ignoring the warning message:

\1 better written as $1 at ./z.pl line 7.
(You are using strict and warnings, right?) Third - what's with the ($a = $a )? Finally, you've inverted the problem. You're replacing everything except characters 6 through 9. You probably want something like:
$a =~ s/^(\S{5})\S{4}/$1xxxx/;
Or, potentially simpler:
$a =~ s/(?<=^\S{5})\S{4}/xxxx/;
But what you really want is still substr.

Replies are listed 'Best First'.
Re^3: howto replace part of a string
by jeanluca (Deacon) on Jun 14, 2006 at 16:08 UTC
    So, now I understand what I was doing (or not doing). I never understood the \1, and I don't know why I do ( $a = $a ) too, I think I once copied it from somewhere without understanding it

    Thanks a lot
    Luca