【SH】対話型シェルスクリプト - (・∀・)イイ!!Memo
を参考に。
#!/usr/bin/perl -w use strict; use encoding('euc-jp'); binmode(STDERR, ':raw :encoding(euc-jp)'); print "文字列を入力してください: \n"; my $input = <>; print "入力された文字列は: $input";
$ perl prompt.perl 文字列を入力してください: あ ああああ euc-jp "\xA2" does not map to Unicode at prompt.perl line 7. 入力された文字列は: あい△△△\xA2
あれ、何かエラー出てる。
入力された文字列の文字コード変換にとまどいがあるみたい。
次の一文を追加してみた。
binmode(STDIN, ':raw :encoding(euc-jp)');
#!/usr/bin/perl -w use strict; use encoding('euc-jp'); binmode(STDERR, ':raw :encoding(euc-jp)'); binmode(STDIN, ':raw :encoding(euc-jp)'); print "文字列を入力してください: \n"; my $input = <>; print "入力された文字列は: $input";
$ perl prompt.perl 文字列を入力してください: あ ああああ 入力された文字列は: あ ああああ
うまいこといったみたい
参考:
I/O Operators operator, i/o operator, io io while filehandle <> @ARGV