[comp.lang.perl] more termcap.pl problems & a quick question

pem@frankland-river.aaii.oz.au (Paul E. Maisano) (02/27/90)

The subroutine Tgoto in termcap.pl does not seem to work.
To fix it I placed "local(@args) = @_;" at the start and replaced
@_ by @args throughout.

This sounds vaguely familiar to me. It might already be fixed in patch 9.

By the way, I might have missed something in the manual but is there some
way to do the reverse of the "ord()" function. Ie. go from a number to
a character. I know that unpack will do it.

The reason I ask is, I needed a function to print out a readable string
which might contain control characters. For example, given "\001x\002"
it would print out "^Ax^B".

What I came up with (rather quickly/hastily) was:

sub p {
    local($str) = @_;
    $str =~ s/([\000-\037])/(($x)=unpack("c", $1),"^".pack("c", $x+0100))/eg;
    print $str;
}

This seems horribly inelegant. Suggestions anyone ?

------------------
Paul E. Maisano
Australian Artificial Intelligence Institute
1 Grattan St. Carlton, Vic. 3053, Australia
Ph: +613 663-7922  Fax: +613 663-7937
Email: pem@aaii.oz.au

pem@frankland-river.aaii.oz.au (Paul E. Maisano) (02/27/90)

In article <1171@frankland-river.aaii.oz.au>, pem@frankland-river.aaii.oz.au (Paul E. Maisano) writes:
> What I came up with (rather quickly/hastily) was:
> 
> sub p {
>     local($str) = @_;
>     $str =~ s/([\000-\037])/(($x)=unpack("c", $1),"^".pack("c", $x+0100))/eg;
>     print $str;
> }
> 
> This seems horribly inelegant. Suggestions anyone ?

I was rather hasty... this is better:
    
sub p {
     local($str) = @_;
     $str =~ s/([\000-\037])/"^".pack("c", ord($1)+0100)/eg;
     print $str;
}

Sorry about that...

------------------
Paul E. Maisano
Australian Artificial Intelligence Institute
1 Grattan St. Carlton, Vic. 3053, Australia
Ph: +613 663-7922  Fax: +613 663-7937
Email: pem@aaii.oz.au

merlyn@iwarp.intel.com (Randal Schwartz) (02/28/90)

In article <1172@frankland-river.aaii.oz.au>, pem@frankland-river (Paul E. Maisano) writes:
| sub p {
|      local($str) = @_;
|      $str =~ s/([\000-\037])/"^".pack("c", ord($1)+0100)/eg;
|      print $str;
| }
[well, he said more than that, but that's the important part... :-]

how about handling DEL too?

sub unctrl {
	local($_) = @_;
	s/([\000-\037\177])/'^'.pack('c',ord($1)^64)/eg;
	$_;
}

print &unctrl("\000\002\n\r\027ABC\177"),"\n";

results in:

^@^B^J^M^WABC^?

print &unctrl("Just another Perl hacker,");
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/