2つのファイルを続けて出力するにはどうしたらいいのだろう。(2-1)
1 / 1-1 / 2 / 2-1
初心者用 Perl講座の課題2-1を試してみる。
とりあえずfood2.txtをつくってみる。
テキストファイルに
Pooh likes honey.
He finds honeycomb and eats honey.
He also likes honey pies.
But, he is often followed by honey bees.
という内容でfood2.txtを作ってみる。
一つのファイルならうまく動いたけれど
以前にやったようにして、food.txtをfood2.txtに置き換えてつくったPerlのスクリプトをeat2.plというファイルにする。
komadas-Computer:~ komada$ chmod +x eat2.pl
komadas-Computer:~ komada$ ./eat2.pl
Pooh likes honey.
He finds honeycomb and eats honey.
He also likes honey pies.
But, he is often followed by honey bees. komadas-Computer:~ komada$
ひとつのファイルを開くのなら、うまく実行できた
2つのファイルはうまく出力できない。
テキストファイルに
#!/usr/bin/perl
open(FILE, "food.txt", "food2.txt");
while(){ print $_;
}
close FILE;
という内容のeat3.plを作って試してみるが、
komadas-Computer:~ komada$ chmod +x eat3.pl
komadas-Computer:~ komada$ ./eat3.pl
Unknown open() mode 'food.txt' at ./eat3.pl line 3.
komadas-Computer:~ komada$
これではうまく動かない。