Guest User

Untitled

a guest
Jun 29th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.04 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4.  
  5. BEGIN {
  6.     no warnings;
  7.     eval q{ use Text::WrapI18N; use Text::CharWidth };
  8.     use warnings;
  9.     if (! $@) {
  10.         # Set up wrap and width functions to point to functions from the modules.
  11.         *wrap = *Text::WrapI18N::wrap;
  12.         *columns = *Text::WrapI18N::columns;
  13.         *width = *Text::CharWidth::mbswidth;
  14.         *mblen = *Text::CharWidth::mblen;
  15.     } else {
  16.         no warnings 'once';
  17.         # Use Text::Wrap for wrapping, but unexpand tabs.
  18.         require Text::Wrap;
  19.         require Text::Tabs;
  20.         sub _wrap { return Text::Tabs::expand(Text::Wrap::wrap(@_)) }
  21.         *wrap = *_wrap;
  22.         *columns = *Text::Wrap::columns;
  23.         # Cannot just use *CORE::length; perl is too dumb.
  24.         sub _dumbwidth { length shift }
  25.         *width = *_dumbwidth;
  26.         *mblen = *_dumbwidth;
  27.     }
  28. }
  29.  
  30. if($ARGV[0] eq 'wrap') {
  31.     $main::columns = $ARGV[2];
  32.     print wrap('', '', $ARGV[1]);
  33. } elsif($ARGV[0] eq 'width') {
  34.     print width($ARGV[1]);
  35. } elsif($ARGV[0] eq 'mblen') {
  36.     print mblen($ARGV[1]);
  37. } else {
  38.     print 'Bad arguments';
  39.     exit 1;
  40. }
  41.  
  42. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment