PL_HW01-3 in Perl

#!usr/bin/perl

unless ($#ARGV==0){
print "Usage : perl  \n";
exit(1);
}
open(INPUT,$ARGV[0]);
@lines=;
while(1){
print "Command List\nWord-count : Count number of Words.\nWord-replace : replace the words \nExit : Exit Program.\n";
print "Input Command : ";
$command=;
print "\n";
chomp $command;

if($command eq "Word-count") {
#Word-Count
%word={};
foreach $_ (@lines) {
@a=split;
for ($n=0;$n<=$#a;$n++) {
$word{@a[$n]}+=1;
}
}
for $w (keys %word){
print "$w : $word{$w}\n" if $word{$w}>0;
}
print "\n[Finished]\n\n";

} elsif($command eq "Word-replace"){
# Word-Replace

while(1) {
print "edit : input a replace word\n";
print "end : end input\n";

print "replace mode >  ";
$sub_cmd=;
chomp $sub_cmd;
if ($sub_cmd eq "edit"){
print "before word : ";
$before=;
print "After word : ";
$after=;
chomp $before;
chomp $after;
for($n=0;$n<=$#lines;$n++) {
$lines[$n] =~ s/${before}/${after}/;
}
}elsif ($sub_cmd eq "end") {
last;
}
}
print "enter output file : ";
$out_file=;
chomp $out_file;
open(OUTPUT,">${out_file}");
print "\n\n";
foreach $_ (@lines) {
print OUTPUT $_;
print $_;
}
print "\n[Finished]\n";
} elsif ($command eq "Exit"){
close(INPUT);
exit(0);

}else{
print "$command\n";
print "You entered a incorret Command.\n";
}
}


'Sorce Bank' 카테고리의 다른 글

Java Binary Tree  (0) 2010.03.14
Python Client  (0) 2010.03.14
Python Server  (0) 2010.03.14
PL HW 01_2 in perl  (0) 2010.03.14
Binary Tree in Ruby  (0) 2010.03.14