フラット ファイル (*.csv) で参照されるロケーション グリッド (AI および 1-9) があり、さまざまな形式で空白やランダムなケース (9-H、@ b 3、e など) が含まれることがあります。 -4、d4、c6、5h、C2、i9、... は、a ~ i と 1 ~ 9 の任意の組み合わせで、空白、~ @、および - を含みます。
このような英数字の抽出を処理するにはどうすればよいでしょうか? 出力は、「メモ」の前の別の列または別のテキスト ファイルにあることが理想的です。スクリプトを読んで、それが何をするかを理解することはできますが、まだスクリプトを書くのに十分ではありません。
サンプル入力ファイル:
Record Notes
46651 Adrian reported green-pylons are in central rack. (e-4)
46652 Jose enetered location of triangles in the uppur corner. (b/c6)
46207 [Location: 5h] Gabe located the long pipes in the near the far corner.
46205 Committee-reports are in boxes in holding area, @ b 3).
45164 Caller-nu,mbers @ 1A
45165 All carbon rod tackles 3 F and short (top rack)
45166 USB(3 Port) in C2
45167 Full tackle in b2.
45168 5b; USB(4 port)
45073 SHOVELs+ KIPER ON PET-FOOD (@g6), ALSO ATTEMPT-STALL AND DRAWCORD.
45169 Persistent CORDS ~i9
45170 Deliverate handball moved to D-2 on instructions from Pete
45440 slides and overheads + contact-sheets to 9-H (top bin).
45441 d7-slides and negatives (black and white)
<eof>
必要な出力 (英数字形式、同じファイルまたは新しいファイルのいずれか)
Record Location Notes
46651 E4
46652 C6
46205 A1
...
46169 I9
つまり、常に後者の文字セットを抽出します。
わかりました、「パターン マッチ (m//) での初期化されていない値 $note の使用」エラーが発生した後、試してみて、部分的に成功しました。
# # starts with anything then space or punctuation then letter then number
if ($note =~ /.*[\s\~\p{Punct}]([a-iA-I])[\s\p{Punct}]*([0-9]).*/) {
$note =~ s/.*[\s\~\p{Punct}]([a-iA-I])[\s\p{Punct}]*([0-9]).*/$1$2/x;
# # starts line with letter then number
} elsif ($note =~ /^([a-iA-I])[\s\p{Punct}]*([0-9]).*/) {
$note =~ s/^([a-iA-I])[\s\p{Punct}]*([0-9]).*/$1$2/x;
# # after punctuation then number
} elsif ($note =~ /.*[\s\p{Punct}]([0-9])[\s\p{Punct}]*([a-iA-I]).*/) {
$note =~ s/.*[\s\p{Punct}]([0-9])[\s\p{Punct}]*([a-iA-I]).*/$2$1/x;
# # beginning of line with number
} elsif ($note =~ /^([0-9])[\s\p{Punct}]*([a-iA-I]).*/) {
$note =~ s/^([0-9])[\s\p{Punct}]*([a-iA-I]).*/$2$1/x;
# # empty line or no record of any grid location except "#7 asdfg" format
} elsif ($note=~ "") {
$note = "##";
}
スクリプトがあまり成功しないのは、99994 や 99993 などのレコードに遭遇したときです。
99999 norecordofgridhere --
99998
99997 ボックス #7 がインボイスなしでアレイに入りました。
オフフィールドを見つけたとき、99996 は h 7 でダウンし、コーチェラは e 8 でした。
99994 個のカートンがオフィスに 4 個のバケツの後
99993 6 個の箱がオフィスのファイル キャビネットの最上段に
出力は次のとおりです。
99999 # # norecordofgridhere --
99998 # #
99997 E 7 ボックス #7 がインボイスなしでアレイに入りました。
99996 E 8 は h 7 でダウンしており、Coachela は e 8 でオフ フィールドを見つけました。
99994 B 4 個のバケツの後、オフィスに 4 カートン
99993 B 6 オフィスのファイル キャビネットの一番上の棚に 6 箱
99994 と 99993 には # があるはずです。どこで失敗しましたか? これを修正するにはどうすればよいですか?
Text::CSV_XS を使用するなど、よりクリーンな方法があると思いますが、モジュールが適切にインストールされていることをテストした後でも、ストロベリー perl で不具合が発生しました。これで、activestateperl に戻りました。