rspishock has asked for the wisdom of the Perl Monks concerning the following question:
Thanks for the help everyone.
To answer your questions, yes I am using use strict, use warnings, and use diagnostics. The purpose of the || is to act as an or operator, allowing either a 'y' or a 'Y' or 'n'.
Dave, thanks for pointing out =~, I had forgot about this and it was exactly what I needed.
Thanks again,
-ryan
Monks, I have a script that will generate random passwords based on user specified criteria. I'm trying to add the ability to export the password to a txt file, however I'm coming up with two small, probably easy to fix errors.
My problem is that when I use eq instead of == for the comparison, the script will not create the txt file.
When I use ==, the script will automatically create the txt file and display the warning that should only be displayed if the user enters something other than "y" or "n".
Below is the segment of code which is causing the problem.
print "Do you want to export your password to a text file? (y/n) "; chomp(my $export = <STDIN>); if ($export == q*y||Y*) { open (FH, '>>password.txt') or die $!; print FH "Your password is: ", @password, "\n"; close FH; } elsif ($export == q*n||N*) { print "Your password is: ", @password, "\n"; } else { print "Enter either y or n to continue. \n" ; }
As I said, I'm sure this is probably a simple error to fix, however, I haven't been able to figure it out yet.
Any help would be appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Text output problem
by toolic (Bishop) on Aug 11, 2011 at 00:08 UTC | |
|
Re: Text output problem
by davido (Cardinal) on Aug 11, 2011 at 00:08 UTC | |
|
Re: Text output problem
by jethro (Monsignor) on Aug 11, 2011 at 00:13 UTC | |
|
Re: Text output problem
by cdarke (Prior) on Aug 11, 2011 at 13:41 UTC |