From: satomichan Date: Thu, 27 Nov 2025 03:44:11 +0000 (+0900) Subject: js版に合わせて変数名変更, コメント追加. コメント(#)読み飛ばし部修正. X-Git-Url: https://satomichan.jp/gitweb/?a=commitdiff_plain;ds=sidebyside;p=tel2ma%2F.git js版に合わせて変数名変更, コメント追加. コメント(#)読み飛ばし部修正. --- 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;