初めてのPerl ~ 11章 ファイルハンドルとファイルテスト ~
練習問題 11.7.1
ユーザから入力ファイル名、出力ファイル名、サブルーチン、置き換え文字列を
入力してもらうようなプログラマを書いてください。
(これらは、コマンドラインから取得するのではなく、対話式に入力してもらうこと)
#! /usr/bin/perl -w
use strict;
use warnings;sub input_line{
print $_[0];
chomp(my $input =);
$input;
}my $input = &input_line("INPUT DATA : ");
my $output = &input_line("OUTPUT DATA : ");
die "There is already file or directory" if -e $output;my $pattern = &input_line("SEARCH PATERN : ");
my $replace= &input_line("trance string : ");open INPUT_FILE,"< $input" or die "Can't open file : $!";
open OUTPUT,"> $output" or die "Can't open file : $!";while(
){
s/$pattern/$replace/gi;
print OUTPUT "$_";
}close INPUT;
close OUTPUT;
参考書
- 作者: ランダル・L.シュワルツ,トムフェニックス,Randal L. Schwartz,Tom Phoenix,近藤嘉雪
- 出版社/メーカー: オライリージャパン
- 発売日: 2003/05
- メディア: 単行本
- 購入: 15人 クリック: 474回
- この商品を含むブログ (273件) を見る