Advertisement
cd62131

split for japanese

May 25th, 2018
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.44 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use utf8;
  5. use open qw(:std :encoding(utf8));
  6. use feature q(say);
  7. sub dq($) {
  8.   my ($s,) = @_;
  9.   return '"' . $s . '"';
  10. }
  11. while (<>) {
  12.   chomp;
  13.   s/(\p{Han}|\p{Hiragana}|\p{Katakana})(?!$)/$1:/g;
  14.   s/(?![:])([[:ascii:]]{2})(?!$)/$1:/g;
  15.   my @d = split /:/;
  16.   my $d1 = dq $d[0];
  17.   my $d2 = dq join '', @d[1..2];
  18.   my $d3 = dq $d[3];
  19.   my $d4 = dq join '', @d[4..6];
  20.   say "$d1,$d2,$d3,$d4";
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement