[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sheflug] Quick PERL job



> 
> I'm wading through regular expressions in the Camel book at the moment
> in the hope of spotting the answer, but perhaps someone could
> short-circuit my readings?
> 
> In a script, I need a way to change a string that may have nulls in it
> to printables only.
> 

This does it (or at least, seems to):

	#!/usr/bin/perl

	$x = "hello\000\000\000 world";

	print length($x) . ":" . $x . "\n";
	$x =~ s/[^[:print:]]//g;
	print length($x) . ":" . $x . "\n";
	## end of script

Btw, in standard shell, the similar would be to pipe the string through:
	tr -cd '[:print:]'

Chris...

-- 
\ Chris Johnson           \
 \ cej [at] nightwolf.org.uk    ~-----,   
  \ http://cej.nightwolf.org.uk/  ~-----------------------------------, 
   \ Redclaw chat - http://redclaw.org.uk - telnet redclaw.org.uk 2000 \____
___________________________________________________________________

Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html

  GNU the choice of a complete generation.