寻求高人指点,代码替换

寻求高人指点,代码替换
哪个好心人可以帮我改一改程序啊,我手里有一个程序,我想哪个高人用另外的代码帮我写出来,就是用不同的代码实现相同的功能。老师留了一个这样的作业,我真的是不会写啊。求助!!!
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;
use File::Spec::Functions;

use constant EZPZDIR => catfile($ENV{HOME}, '.ezpzrc');
use constant DICTIONARIES => catfile(EZPZDIR, 'dictionaries');
use constant ADDITIONS => catfile(EZPZDIR, 'additions');
use constant QUIT => "^D on Linux, ^Z on Windows, to exit";

my %options;

getopts('ca', \%options);

if (defined $options{'c'} && defined $options{'a'}) {
die "Use either the -a or -c flag, not both.\n";
}

if(!(-e EZPZDIR) || !(-d EZPZDIR)){
ezpzConfigure();
ezpzConfigurationMode();
} elsif (defined $options{'c'}){
ezpzConfigurationMode();
} elsif(defined $options{'a'}){
ezpzAdditionMode();
} else {
ezpzNormalMode();
}

sub getDictionaries {
my $handle;
open($handle, DICTIONARIES)
or die "Can't open " . DICTIONARIES . ": $!\n";
my @retval = <$handle>;
return @retval;
}

sub ezpzConfigure {
mkdir(EZPZDIR)
or die "Can't create " . EZPZDIR . ": $!\n";
my $handle;
open($handle, '>', DICTIONARIES)
or die "Can't create " . DICTIONARIES . ": $!\n";
close($handle);
open($handle, '>', ADDITIONS)
or die "Can't create " . ADDITIONS . ": $!\n";
}

sub ezpzConfigurationMode {
print "Welcome to the ezpz word puzzle configurer!\n";
my @dictionaries = getDictionaries();
my $dictionaries = scalar @dictionaries;
my $dictionary;
print "Currently you have $dictionaries " .
(($dictionaries == 1) ? "dictionary\n" : "dictionaries\n");
if($dictionaries > 0){
foreach $dictionary (@dictionaries){
print "\t$dictionary";
}
} else {
print "On Linux /usr/share/dict/words is a good choice!\n";
}
print "Feel free to specify a new dictionary \n\t(" . QUIT . "):\n";
while(my $dict = <>){
chomp $dict;
if(-f $dict){
add2File($dict, DICTIONARIES);
print "Great, I added $dict to your list\n";
} else {
print "Sorry $dict didn't look like an existing plain text file\n";
}
}
}

sub ezpzAdditionMode {
print "Feel free to add new words to you additions file \n\t(" . QUIT . "):\n";
while(my $word = <>){
chomp $word;
add2File($word, ADDITIONS);
print "Great, I added $word to your list\n";
}
}

sub add2File {
my ($line, $file) = @_;
my $handle;
open($handle, '>>', $file)
or die "Can't open $file for appending: $!\n";
print $handle "$line\n";
}

sub ezpzNormalMode {
print "Welcome to the ezpz word puzzle helper!\n";
print "\t spaces or _ match any letter\n";
print "\t. matches non-vowels\n";
print "\t, matches vowels (y, a semi-vowel, counts as a vowel)\n";
print "\t All searches are case insensitive.\n";
print "\t (" . QUIT . ")\n";

my @dictionaries = getDictionaries();
unshift @dictionaries, ADDITIONS;
my $dictionary;

while(my $word = <>){
chomp $word;
$word =~ s/ /\[a\-z\]/g;
$word =~ s/_/\[a\-z\]/g;
$word =~ s/\./\[\^aeiouy\]/g;
$word =~ s/,/\[aeiouy\]/g;
$word = "^$word\$";
my @results;
print "searching...\n";
my $pipeh;
foreach $dictionary (@dictionaries){
open $pipeh, "grep -i $word $dictionary |" or
die "Cannot open pipe to grep: $!";
while(<$pipeh>){
push @results, $_;
}
close $pipeh;
}
#remove duplicates,
#see: http://www.stonehenge.com/merlyn/UnixReview/col11.html
my %temp = ();
@results = grep ++$temp{$_} < 2, @results;
#print them
foreach (sort @results){
print;
}
print "...finished.\n";
}
}