Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use utf8;
- use open qw(:std :encoding(utf8));
- sub num_zen($);
- sub zen_num($);
- sub num_zen($) {
- my $s = shift;
- my $zen = [ split '', q(0123456789) ];
- $s =~ s/(?<![0-9])(?![0-9]{2}(?:\D|\b))[0-9]+/
- join '', map { $$zen[$_] } split '', $&
- /egx;
- return $s;
- }
- sub zen_num($) {
- my $s = shift;
- my $zen = [ split //, q(0123456789) ];
- my $tab = { map { $$zen[$_], $_ } 0 .. 9 };
- $s =~ s/(?<![0−9])[0-9]+/
- join '', map { $$tab{$_} } split '', $&
- /egx;
- return $s;
- }
- my $p = tell DATA;
- while (<DATA>) {
- print num_zen $_;
- }
- seek DATA, $p, 0;
- while (<DATA>) {
- print zen_num $_;
- }
- seek DATA, $p, 0;
- while (<DATA>) {
- print num_zen zen_num $_;
- }
- __DATA__
- 1 11 111 1111 1 11 111 1111
- a0a a00a a000a あ0あ あ00あ あ000あ
- 00 00 00 00
- 000 000 000 000 000 000 000 000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement