On Sep 27, Jeff 'japhy' Pinyan said: >On Sep 26, [EMAIL PROTECTED] said: > >>Does anyone have a short routine for displaying mask on some values and >>displaying the value of the last four? For example, alot of site display >>credit card numbers like xxxx1234 which shows only the last four. >> >>I know how to use the substr but what about replacing the preceding values >>with xxxx? > >You could use a regex: > > $string = "1234567890"; > $string =~ s/.(?=.{4})/x/g;
You could also use: $string =~ s/(.*)(.{4})/"x" x length($1) . $2/e; It matches all but the last four characters to $1, and those last four characters go into $2. Then the right-hand side is evaluated as code (because of the /e modifier on the regex). We get an "x" for each character in $1, and then just tack on $2. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]