my $saved_pass = 'bd0e9f94ce671b3cdd13081fa5a8b32f9ccd9ebf'; my $eword = 'bd0e9f94ce671b3cdd13081fa5a8b32f9ccd9ebf'; my $passwd_check; $saved_pass eq $eword ? $passwd_check = "good" : $passwd_check = "fail"; print $passwd_check;
fail
my $saved_pass = 'bd0e9f94ce671b3cdd13081fa5a8b32f9ccd9ebf'; my $eword = 'bd0e9f94ce671b3cdd13081fa5a8b32f9ccd9ebf'; my $passwd_check = $saved_pass eq $eword ? "good" : "fail"; print $passwd_check;
good

I have do admit that I don't really get why. Anyone care to explain?
update: Got it (from perlop):
Because this operator produces an assignable result, using assignments without parentheses will get you in trouble. For example, this:
$a % 2 ? $a += 10 : $a += 2
Really means this:
(($a % 2) ? ($a += 10) : $a) += 2
Rather than this:
($a % 2) ? ($a += 10) : ($a += 2)
so what you wrote really means:
($saved_pass eq $eword ? $passwd_check = "good" : $passwd_check ) += "fail";
perlop also says that you can assign to the ternary operator if both arguments between the ? and : are valid lvalues.
So the code comes down to:
if ($saved_pass eq $eword) { $passwd_check = "fail"; }else{ $passwd_check = "fail"; }
In words: assign "fail" to $passwd_check or $passwd_check :-)

In reply to Re: Problem comparing SHA1 string from db, with hashed login password by Golo
in thread Problem comparing SHA1 string from db, with hashed login password by hsinclai

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.