Jeff 'Japhy' Pinyan wrote:
> 
> On Jul 11, [EMAIL PROTECTED] said:
> 
> >I am trying to create a sub routine to remove non-printable chars  from a
> >string, and am stuck on how I should approach this.
> 
> Well, you don't need a subroutine -- just a substitution.
> 
> If you're using perl 5.6, you can do:
> 
>   $string =~ s/[[^:print:]]+//g;
> 
> Before perl 5.6, you can do:
> 
>   $string =~ s/[^ -~]+//g;
> 
> But it's probably faster (in either version) to use tr/// instead of
> s///g:
> 
>   $string =~ tr/ -~//cd;

Don't forget that \t, \r, \n, and \f are printable too.

  $string =~ tr/\t\r\n\f -~//cd;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to