sulfericacid
Programmer
I was wondering if you could help me figure out what's wrong with the script below. I can't get it to the point where they guess a 2nd time and get another valid character right, it adds it to $known. It's only doing one s/// which is the latest one instead of all of them.
Ie:
Secret word is "apple"
User searches A for first letter and it prints "a****"
User searches again for P and it prints "*pp**" instead of "app**.
#!/usr/bin/perl -w
use strict;
my $info = "an apple aaron";
my $guess = 0;
until ($guess eq $info) {
print "Guess character: ";
$guess = <STDIN>;
$guess =~ s/$guess/$guess /;
my $known = $info;
$known =~ s/[^$guess]/\*/g;
my $knownadd = $known; # save $known to prevent variable overwriting
# so we can add more correct guesses later
$knownadd =~ s/[^$guess]/\*/g;
print "$info\n";
print "$known\n";
print "$knownadd\n";
}
"Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid
Ie:
Secret word is "apple"
User searches A for first letter and it prints "a****"
User searches again for P and it prints "*pp**" instead of "app**.
#!/usr/bin/perl -w
use strict;
my $info = "an apple aaron";
my $guess = 0;
until ($guess eq $info) {
print "Guess character: ";
$guess = <STDIN>;
$guess =~ s/$guess/$guess /;
my $known = $info;
$known =~ s/[^$guess]/\*/g;
my $knownadd = $known; # save $known to prevent variable overwriting
# so we can add more correct guesses later
$knownadd =~ s/[^$guess]/\*/g;
print "$info\n";
print "$known\n";
print "$knownadd\n";
}
"Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid