Newsgroups: comp.lang.perl
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:
print &unctrl("Just another Perl hacker,");
%%
Date: 27 Feb 90 17:48:36 GMT
From: merlyn@iwarp.intel.com (Randal Schwartz)
for (split(/(.)/,"Just another Perl hacker,")) {print if $_;}
%%
Date: 28 Feb 90 01:32:25 GMT
From: merlyn@iwarp.intel.com (Randal Schwartz)
@a=<;echo Just another Perl hacker,>; print join(" ",@a);
%%
Date: 28 Feb 90 01:51:32 GMT
From: merlyn@iwarp.intel.com (Randal Schwartz)
mkdir("/tmp/$$",0777); chdir "/tmp/$$";
grep(open(X,">$_"),"1Just","2another","3Perl","4hacker,");
print join(" ",grep(s/^.//,<*>)); chdir ".."; system "rm -rf $$";
%%
Date: 28 Feb 90 02:03:37 GMT
From: merlyn@iwarp.intel.com (Randal Schwartz)
$_ = <<END; s/../pack('C',hex($&))/ge; print;
4a75737420616e6f74686572205065726c206861636b65722c
END
%%
Date: 28 Feb 90 16:09:35 GMT
From: merlyn@iwarp.intel.com (Randal Schwartz)
$\="hacker,";$,="another ";print"Just ","Perl ";
%%
Date: 28 Feb 90 22:45:45 GMT
From: tneff@bfmny0.UU.NET (Tom Neff)
@a=split(//,'1111211111131223311361214223121412311341121111222123616111111122'.
'21233212615112114212321211121111222123321120');for$r(@a){for(1..$r){vec($s,$i,
1)=$v;$i++;}$v^=1;}print"$s\n";
%%
Date: 1 Mar 90 06:27:25 GMT
From: jgreely@giza.cis.ohio-state.edu (J Greely)
print reverse(split(/!?/,join(' ',sort split(/ /,"tsuJ rehtona lrep ,rekcah"))));
%%
Date: 1 Mar 90 17:06:10 GMT
From: merlyn@iwarp.intel.com (Randal Schwartz)
for('Snobol','Perl'){print"Just another $_ hacker,\n";}
%%
Date: 5 Mar 90 17:39:29 GMT
From: merlyn@iwarp.intel.com (Randal Schwartz)
pipe(R,W);if(!fork){exit print W"Just another Perl hacker,";}close(W);print<R>;
%%
Date: 6 Mar 90 11:07:32 GMT
From: Andrew.Vignaux@comp.vuw.ac.nz (Andrew Vignaux)
@l = split (/(..)/,'1a7r4J1n0a7e7c1o8n248o1t4u8v4s7.207l27547a7n7g1h'.
'0 511e3h7.8i564t3a6P1r7p8c8e6e3c3k7e3e533r7r286r6l4 6 1 8,7l7 3,');
srand; $_=3*int(rand(2))+2; /^$_/;
foreach (split(//,&g)) {/^$_/;print &g;} print "\n";
sub g {join('',grep(s/^.//,grep(//,@l)));}
%%
Larry> for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
Larry> {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";
Larry> And a special version just for Randal:
Larry> grep(do{for(ord){$i+=$_%8;grep(vec($s,$i++,1)=1,5..($_>>3||print"$s\n"));}},
Larry> (@x=split(//,"))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)\7")));
%%
Date: 6 Mar 90 18:08:23 GMT