初めてのPerl 第5章入出力 練習問題1

  • 問題文 catのような振る舞いをするプログラムを書いてください。ただし、このプログラムは行を逆に表示します。

以下記述内容です。

use strict;
use warnings;
use Data::Dumper;

#コマンドラインで受け取ったファイルの内容を末尾から表示する
print reverse <>;

上記プログラムを実行する際は以下のような引数を与えて実行しました。

perl practice1.pl ./tac fred barney betty

引数に与えたのはファイル名となり、各ファイルには以下の内容が記述してあります。

name is ファイル名
a
b
c
d
e
f
ここまで   

実行結果は以下のようになります。

ここまで
g
f
e
d
c
b
a
name is betty
ここまで
f 
e
d
c
b
a
name is barney
ここまで
g
f
e
d
c
b
a
name is fred
ここまで
g
f
e
d
c
b
a
name is tac