3つ以上のファイルの開け方はどうするのだろう。
前へ /
人力検索でperlcodesampleさんに3つ以上のファイルの開けるスクリプトを教えていただきました。まだまだ慣れなくて、このスクリプトの動かし方がまだうまくできません。
まずfood3.txtを作ってみる。
food.txtとfood2.txtは作ったのでfood3.txtを作る。
Pooh is eating honey pies.
He is eating tree honey pies.
He is eating two apple pies.
He has a great appetite.
この内容をfood3.txtという名前で保存
sample.plという名前をつける
#!/usr/bin/perl
use strict;
use warnings;
my @files=@ARGV;
foreach my $file (@files){
open( my $fh, "<", $file )
or die "Cannot open $file";
while( my $line=<$fh>){
print $line;
}
close($fh);
}
_END_
教えていただいたスクリプトにsample.plという名前をつけて保存。
コマンドライン引数でファイル名を渡すのは、これでいいのでしょうか。
ターミナルで
perl sample.pl food.txt food2.txt food3.txt
と入力してみる。
komadas-Computer:~ komada$ chmod +x sample.pl
komadas-Computer:~ komada$ perl sample.pl food.txt food2.txt food3.txt
Bareword "_END_" not allowed while "strict subs" in use at sample.pl line 16.
Execution of sample.pl aborted due to compilation errors.
komadas-Computer:~ komada$
なにかが足りないのかな。