From 50e58df28b31499a517b9edd0fb2ab13fd8a7391 Mon Sep 17 00:00:00 2001 From: satomichan Date: Thu, 27 Nov 2025 12:44:11 +0900 Subject: [PATCH] =?utf8?q?js=E7=89=88=E3=81=AB=E5=90=88=E3=82=8F=E3=81=9B?= =?utf8?q?=E3=81=A6=E5=A4=89=E6=95=B0=E5=90=8D=E5=A4=89=E6=9B=B4,=20?= =?utf8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E8=BF=BD=E5=8A=A0.=20?= =?utf8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88(#)=E8=AA=AD=E3=81=BF?= =?utf8?q?=E9=A3=9B=E3=81=B0=E3=81=97=E9=83=A8=E4=BF=AE=E6=AD=A3.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- tel2ma.pl | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tel2ma.pl b/tel2ma.pl index 83462e5..a33a0e1 100755 --- a/tel2ma.pl +++ b/tel2ma.pl @@ -12,7 +12,7 @@ ex) $ ./tel2ma.pl 033xxx-yyyy _END_OF_USAGE_ } -# Copyright 2025 FUKUDA Satomi (https://satomichan.jp/tel2ma) +# Copyright 2025 FUKUDA Satomi (https://satomichan.jp/about_tel2ma) # # Licensed under the Apache License, Version 2.0 (the “License”); # you may not use this file except in compliance with the License. @@ -63,29 +63,32 @@ usage(), exit unless $tel =~ /^0.{9}$/; foreach my $line () { chomp $line; - $line =~ s/#.?$//; - $line =~ s/\s+?$//; + $line =~ s/#.*$//; + $line =~ s/\s+$//; next unless $line; - my( $pref, $ma, $city, $range, $area ) = split(/\s+/, $line); + my( $pref, $ma, $area_codes, $range, $munics ) = split(/\s+/, $line); - my @cc = sort { length $b <=> length $a } split(/,/, $city); - foreach my $c (@cc) { + my @ac = sort { length $b <=> length $a } split(/,/, $area_codes); + foreach my $ac (@ac) { #市外局番ごと - next unless $tel =~ /^$c/; + next unless $tel =~ /^$ac/; - foreach my $r ( split(/,/, $range) ) { + foreach my $r ( split(/,/, $range) ) { #ひと番号領域ごと $r =~ s/(\d)~(\d)$/[$1-$2]/; if( $tel =~ /^0$r/ ) { - my $end = substr($tel, -4); - my $sta = substr($tel, length $c, (6 - length $c)); - print "$c-$sta-$end ${ma}MA $area\n"; + #市内局番 + my $exch = substr($tel, length $ac, (6 - length $ac)); + #加入者番号 + my $subsc = substr($tel, -4); + + print "$ac-$exch-$subsc ${ma}MA $munics\n"; exit; } - } #r - } #c + } #ひと番号領域ごと + } #市外局番ごと } #line exit; -- 2.43.0