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.


In reply to Text output problem by rspishock

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.