fork download
  1. #!/usr/bin/env perl
  2. use utf8;
  3. use Encode;
  4.  
  5. die "input align regexp as argment.\n" if @ARGV == 0;
  6. my ( $search, $left_align ) = @ARGV;
  7. my ( @matrixs_ref, @column_widths );
  8.  
  9. sub true_length {
  10. my ( $raw_line, $j, $e ) = ( shift, 0, 0 );
  11. for ( split( //, Encode::decode( 'UTF8', $raw_line ) ) ) {
  12. /\P{ascii}/ ? ++$j:
  13. /\N/ ? ++$e:
  14. next;
  15. }
  16. 2 * $j + $e;
  17. }
  18.  
  19. while ( chomp( my $raw_line = <STDIN> ) ) {
  20. my @columns = split( /$search/, $raw_line );
  21. push @matrixs_ref, \@columns;
  22. # extend list to modify map working by longer list
  23. push( @column_widths, 0 ) while ( $#columns - $#column_widths > 0 );
  24. @column_widths = map {
  25. $column_widths[$_] > true_length( $columns[$_] )
  26. ? $column_widths[$_]
  27. : true_length( $columns[$_] );
  28. } ( 0 .. $#column_widths );
  29. }
  30.  
  31. for my $divided_ref (@matrixs_ref) {
  32. my $i = 0;
  33. for (@$divided_ref) {
  34. if ($left_align) {
  35. print;
  36. print q{ } x ( $column_widths[ $i ] - true_length($_) )
  37. unless ( $i == -1 + @$divided_ref );
  38. }
  39. else {
  40. print q{ } x ( $column_widths[ $i ] - true_length($_) );
  41. print;
  42. }
  43. }
  44. continue {
  45. print q{ } unless ( ++$i == @$divided_ref );
  46. }
  47. print "\n";
  48. }
  49.  
Runtime error #stdin #stdout #stderr 0.19s 76848KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
===SORRY!===
utf8 is a builtin type, not an external module