http://qs321.pair.com?node_id=612821

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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: incorrect results
by ptum (Priest) on Apr 30, 2007 at 18:26 UTC

    Well, it isn't very easy to see what your problem is, without a little more code and some decent <code> tag formatting. Taking a wild guess, though, I'd say you might try 'eq' when comparing your parameters, since they seem to be string values. As it is, you're comparing their numerical value with '=='.

    A reply falls below the community's threshold of quality. You may see it by logging in.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: incorrect results
by shigetsu (Hermit) on Apr 30, 2007 at 18:32 UTC

    You could always dump the structures to have verified that they contain what you expected. See Data::Dumper therefore.

    Or use Super Search (keyword: 'Data::Dumper') which will turn up many examples that are used in actual code.

Re: incorrect results
by RMGir (Prior) on Apr 30, 2007 at 18:41 UTC
    _Wild_ guess, but you're comparing $first->{$t1}->{$array[$i]} using ==.

    That works fine for numbers.

    But then you're using "chomp", which makes sense for a newline-terminated string.

    Are you sure you wanted == in your unless, rather than eq?


    Mike
      There are both integers and strings in the compared values.
        There are both integers and strings in the compared values.

        (Caveat: I've not been following the previous discussion.)

        Strictly speaking this does not make sense. Even more strictly you can use Scalar::Util's dualvar() to create a scalar that will have two completely unrelated values in "numeric context" and in "string context" (note that these are not even precisely defined in Perl 5) respectively, but take this as an aside: generally perl will do what you mean in a very convenient way, with automatic conversions between numbers and strings. So you probably have strings that may occasionally look like numbers and you may want to sort numerically in the latter case. You may also want to do some checks to verify if that is the case.

      A reply falls below the community's threshold of quality. You may see it by logging in.