#!/usr/bin/perl -w # encode_template.pl - Don Yang (uguu.org) # # [ .. # = space # ^ .. ~ = char # ] = newline # # 07/01/07 use strict; sub EncodeRange($$$) { my ($start, $end, $val) = @_; for(; $val > abs($end - $start + 1); $val -= abs($end - $start + 1)) { print chr($end); } print chr($start < $end ? $start + ($val - 1) : $start - ($val - 1)); } while(my $line = <>) { chomp $line; while( $line ne '' ) { if( $line =~ s/^(\s+)(.*?)$/$2/ ) { # Encode consecutive whitespace EncodeRange(ord('['), ord('#'), length($1)); } else { # Encode consecutive non-whitespace $line =~ s/^(\S+)(.*?)$/$2/ or die $!; EncodeRange(ord('^'), ord('~'), length($1)); } } # Newline print ']'; } print "\n";