in reply to pattern match showes true

As others said, != is a numeric comparison; it will compare the numeric value of the left and right operands. Since your strings don't have digits at the beginning, their numeric value will be 0. Taking the numeric value of strings such as yours will trigger a warning if you have warnings enabled (which you should!) to alert you to a possible error on your part.

ne is the equivalent operator for string comparisons. Similarly, the numeric operators ==, <, >, <=, >=, and <=> have string equivalents eq, lt, gt, le, ge, and cmp.

Your other problem is using a \ in a double-quoted string. It has a special meaning as an escape character there. Use \\ to get a literal single backslash.

Replies are listed 'Best First'.
Re^2: pattern match showes true
by Anonymous Monk on Jul 31, 2007 at 18:47 UTC
    hi, I am still not able to match the values. I have a problem comparing values like
    $preprod->{$siebdb} = $k; #$k is /siebprod/db13/PRODDB/log2/ $prod->{$siebdb} = $j; # $j is /preprod/db12/PREPRODDB/log2/
    any idea how I should compare these?
      Run the following, and tell us what the output is:

      $preprod->{$siebdb} = $k; print "[$k]\n"; $prod->{$siebdb} = $j; print "[$j]\n"; if ( $preprod->{$siebdb} eq $prod->{$siebdb} ) { print "SAME\n" } else { print "DIFFERENT\n" }

      Do what FunkyMonk said. Also, when you show us what you are doing, you're being just a little bit too terse; seeing larger parts of your actual code might help us help you better (not too large - remove as much as you can while still leaving enough to create the problem).

      I can think of three possible problems you might be having, other than simple syntax misuse: one of your strings might have a newline at the end, making them not exactly equal; $prod and $preprod could be referring to different hashes than you expect; $siebdb could be something different than you expect either when storing the values in the hash or when doing the comparison.

      We'd really have to see more of your code to tell what's up.

        hi again, I am building two saperate hashes as
        my($q1,$a1) = split(/=/); $prod->{$environment}{$dbname}{$q1} = $a1; my($rt,$ap) = split(/=/); $preprod->{$env}{$database}{$rt} = $ap; and then comparing the values as if ($preprod->{$env}{$database}{$rt} ne $prod->{$environment}{$dbname} +{$q1) { print "$preprod->{$env}{$database}{$rt}\n" }
        I get all the values correct except
        #$a1 is /siebprod/db13/PRODDB/log2/ #$ap is /preprod/db12/PREPRODDB/log2/