develooper Front page | perl.beginners | Postings from December 2002

Re: check against two different passwords.

Thread Previous
From:
Rob Dixon
Date:
December 23, 2002 15:26
Subject:
Re: check against two different passwords.
Message ID:
20021223232600.64320.qmail@onion.perl.org
Nearly, but it needs to be:

    if ( $qs ne $secret_word_guest and $qs ne $secret_word )
                                   ^^^
or consider

    unless (grep $qs eq $_, ($secret_word, $secret_word_guest) )
    {
        :
    }

Cheers,

Rob


"John W. Krahn" <krahnj@acm.org> wrote in message
news:3E078134.78AF2F71@acm.org...
> David Gilden wrote:
> >
> > Hello,
>
> Hello,
>
> > in the following
> >
> > # Goal:  check against two different passwords.
> >
> > #!/usr/bin/perl
> > my $qs = 'c';
> > my $secret_word  = 'a';
> > my $secret_word_guest  = 'b';
> >
> > if ($qs !~ /$secret_word_guest|$secret_word/) {
>
> You need boundaries for an exact match.
>
>  if ( $qs !~ /^(?:$secret_word_guest|$secret_word)$/ ) {
>
>
> >     print "fail\n";
> >         } else {
> >         print "go, ok\n";
> >         }
> >
> > another version:
> >
> > #!/usr/bin/perl
> >
> > my $qs = "a";
> > my $secret_word  = 'a';
> > my $secret_word_guest  = 'b';
> >
> > if ($qs ne ($secret_word_guest || $secret_word)) {
>
>  if ( $qs ne $secret_word_guest or $qs ne $secret_word ) {
>
>
> > print "fail\n";
> > } else { print "go, ok\n";}
> >
> > --------
> > the original works fine!
> > if ($qs ne  $secret_word) {
> > print "fail\n";
> > exit;
> > }
> >
> > What should happen is that if $secret_word OR $secret_word_guest does
not Match $qs
> > Then it should print 'Fail'.
> >
> > The above behaves correctly, but when I try to bring a second test,
> > it fails....
> >
> > I can not seem to get this to do what i want!
> > Can any one show me by example what is wrong.
>
>
>
> John
> --
> use Perl;
> program
> fulfillment



Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About