Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Monks, I most humble myself this morn. I'm having a spot of trouble with eq. This is the code:
if ($usrfile{password} eq $password) {
. It's returning false, when I know, by means of printing, that they are the same string. It's not numerical, anyone out there know why???

Replies are listed 'Best First'.
Re: eq is being stubborn
by lhoward (Vicar) on Oct 30, 2000 at 07:06 UTC
    Are you sure that they are exactly the same? No leading or trailing spaces (or other invisible type characters)? I've encountered this type problem enough and I can almost guarantee you that your problem is trailing-spaces (or something like that).
RE: eq is being stubborn
by lachoy (Parson) on Oct 30, 2000 at 08:50 UTC

    Also, as a debugging tip, it's usually helpful to print out the values of things like this in some sort of delimiters:

    warn " Compare <<$usrfile{password}>> to <<$password>>"; if ( $usrfile{password} eq $password ) { ... blah blah blah... }

    I'm ashamed to admit that this has saved more time than I can shake a stick at.

      No shame, no shame, print is the poor man's debugger. =)

      --
      $you = new YOU;
      honk() if $you->love(perl)

      I use that delimiter trick often, and when I'm really paranoid (or I know my strings have unpleasant characters in them) I do something like:
      print unpack('H*',$usrfile{$password}) ."\n". unpack('H*',$password);
      And I can usually see the difference then. I hope!
RE: eq is being stubborn
by extremely (Priest) on Oct 30, 2000 at 07:47 UTC
    I vote with lhoward.. try this: <code> chomp($usrfile{password); chomp($password); if ($usrfile{password} eq $password) {

    --
    $you = new YOU;
    honk() if $you->love(perl)