Madhu Reddy wrote: > > > > i don't thing the above will work. try: > > > > > > > > for(split(//)){ > > > > if(ord < 32 || ord > 126){ > > > > print "Char is non printable char\n"; > > > > }else{ > > > > print "$_\n"; > > > > } > > > > } > > I want to do following, if any char is ASCII value of > 10 or 13, i want to make that char as null > > like following > $_ = "hello\n\t\r world"; > for(split(//)){ > if(ord() < 32 || ord() > 126){ > if (ord() eq 10 ) { > =====> make this char as null > } > if (ord() eq 13 ) { > =====> make this char as null > } > print "Char is non printable char\n"; > }else{ > print "$_\n"; > } > }
That's certainly a lot of code for a simple requirement! The best way is to use Perl's translate operator. This: $_ =~ tr/\r\n/\0\0/ will replace CR and LF with null characters as you asked, but I suspect that you want them removing altogether, in which case: $_ =~ tr/\r\n//d is what you want. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]