Skip to content

Instantly share code, notes, and snippets.

@jgarlick
Created August 6, 2012 10:21
Show Gist options
  • Save jgarlick/3273238 to your computer and use it in GitHub Desktop.
Save jgarlick/3273238 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/perl
while (chomp($t=)){
$c=1; $d=1; @b=();
foreach (split(/;/,$ARGV[0])){
if( /^al/ ){ tr/0-9//cd; $c-=$_; $c=1 if $c<1; }
elsif( /^ar/ ){ tr/0-9//cd; $c+=$_; }
elsif( /^tl/ ){ $c=1; }
elsif( /^tr/ ){ $c=length $t; }
elsif( /^go/ ){ tr/0-9//cd; $c=$_; }
elsif( /^cb/ ){ @b=(); }
elsif( /^jn/ ){ $t=join( "",@b); }
elsif( /^ex/ ){ tr/0-9//cd; ($t,$b[$_])=($b[$_],$t); }
elsif( /^ed/ ){ $t=substr($t,0,$c-1).substr($t,$c,length $t); }
elsif( /^ee/ ){ $c-- if $c>1; $t=substr($t,0,$c-1).substr($t,$c,length $t); }
elsif( /^dr/ ){ $d=$c; }
elsif( /^da/ ){ $d=1; $c=length $t; }
elsif( /^xd/ ){ tr/0-9//cd; ($l,$h)=sort {$a<=>$b}($c,$d); $b[$_]=substr($t,$l-1,$h-$l+1);
$t=substr($t,0,$l-1).substr($t,$h,length $t); }
elsif( /^xc/ ){ tr/0-9//cd; ($l,$h)=sort {$a<=>$b}($c,$d); $b[$_]=substr($t,$l-1,$h-$l+1); }
elsif( /^xp/ ){ tr/0-9//cd; $t=sprintf("%-*s%s%s", $c-1, substr($t,0,$c-1), $b[$_],
substr($t,$c-1,length $t)); $c+=length $b[$_]; }
else{ @m=split(/([^@])\'+/); @m=($m[0].$m[1],$m[2].$m[3],$m[4].$m[5]);
foreach $m (@m) { $m =~ s/@\'/\'/g; $m =~ s/@@/@/g; }
if( /^es/ ){ $t=sprintf("%-*s%s%s", $c-1, substr($t,0,$c-1), $m[1],
substr($t,$c-1,length $t)); $c+=length $m[1]; }
elsif( /^sr/ ){ $o= index($t,$m[1],$c-1); $c=$o+1 unless $o==-1; }
elsif( /^sl/ ){ $o=rindex($t,$m[1],$c-1); $c=$o+1 unless $o==-1; }
elsif( /^tc/ ){ ($l,$h)=sort {$a<=>$b}($c,$d); $_=substr($t,$l-1,$h-$l+1);eval "tr/$m[1]/$m[2]/";
$t=substr($t,0,$l-1).$_.substr($t,$h,length $t); }
elsif( /^ss/ ){ ($l,$h)=sort {$a<=>$b}($c,$d); $_=substr($t,$l-1,$h-$l+1);s/$m[1]/$m[2]/g;
$t=substr($t,0,$l-1).$_.substr($t,$h,length $t); }
}
}
print "=>$t\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment