use v6-alpha; use Getopt::Std; my %opts = getopts("benstuv"); %opts++ if %opts | %opts; %opts = 0 if %opts; # unbuffer output if %opts; my $empty = 0; # for -s option my $linenum = 1; while $_ = =<> { # squeeze runs of blank lines to one if %opts { next if ! rx:P5/./ && $empty++; } else { $empty = 0; } $_ ~~ s:P5:g[\t] = "^I" if %opts; $_ ~~ s:P5:g[(.)] = backwhack($0) if %opts; $_ ~= "$" if %opts; if %opts { say sprintf "%6d %s", $linenum++, $_; } elsif %opts { if rx:P5/./ { say; } else { say sprintf "%6d %s", $linenum++, $_; } } else { say; } } sub backwhack ($ch) { given ord $ch { when 0x00 .. 0x1f { "^" ~ chr 0x40 + $_ } # the spec used octal when ({$_ > 0x7f}) { "U+" ~ "$_".fmt("%x") } # but this is the unicode era default { $ch } } }