Re: substr parsing mask
On Sep 29, [EMAIL PROTECTED] said: >I got it to work after adding a new var in apache modperl environment. > >This works: > $acct_no = $xgi->param("acct_no"); > print substr($acct_no, 0, 4, "x" x (length($acct_no)-4)); > >This did NOT work: > print substr($xgi->param("acct_no"), length($xgi->param("acct_no"))-4,4); They're not the same code. print substr( $xgi->param('acct_no'), 0, 4, "x" x (length($xgi->param('acct_no')) - 4) ); -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ what does y/// stand for? 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]
Re: substr parsing mask
I got it to work after adding a new var in apache modperl environment. This works: $acct_no = $xgi->param("acct_no"); print substr($acct_no, 0, 4, "x" x (length($acct_no)-4)); This did NOT work: print substr($xgi->param("acct_no"), length($xgi->param("acct_no"))-4,4); Any explanation would be great. -rkl I tried to save a line by using > On Sep 27, [EMAIL PROTECTED] said: > >>> substr($string, 0, -4, "x" x (length($string) - 4)); >> >>I couldn't get this to work correctly. it only returns the 4 characters >> of >>the string whcih is correct. But it did not replace the preceding >>characters with . > > It works for me: > > [EMAIL PROTECTED] [11:47am] ~ #103> perl -l > $string = join '', .. 9; > substr($string, 0, -4, "x" x (length($string) - 4)); > print $string; > __END__ > xx6789 > > -- > Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ > RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ > what does y/// stand for? 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]
Re: substr parsing mask
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 1234 which shows only the last four. >> >>I know how to use the substr but what about replacing the preceding values >>with ? > >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/ what does y/// stand for? 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]
Re: substr parsing mask
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 1234 which shows only the last four. > >I know how to use the substr but what about replacing the preceding values >with ? You could use a regex: $string = "1234567890"; $string =~ s/.(?=.{4})/x/g; That means "for each character that is followed by four characters (at least), replace it with an 'x'". That means that $string will become "xx7890". You could also use substr(): substr($string, 0, -4) = "x" x (length($string) - 4); The right-hand side makes a string of x's as long as the string is, minus four. So for "1234567890", which has length 10, the right-hand side is a string of 6 x's, "xx". The left-hand side gets a substring of $string starting at the beginning and ending four characters from the end. We can CHANGE the return value of substr(): $name = "jeff"; substr($name, 0, 1) = "J"; print $name; # Jeff This means we change all but the last 4 characters of $string to a string of x's as long as that beginning chunk of string. You can also put the replacement value as the fourth argument to the substr() function. substr($string, 0, -4, "x" x (length($string) - 4)); -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ what does y/// stand for? 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]
substr parsing mask
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 1234 which shows only the last four. I know how to use the substr but what about replacing the preceding values with ? thanks, -rkl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]