Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

incorrect results

by Anonymous Monk
on Apr 30, 2007 at 18:07 UTC ( #612821=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://612821]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2021-12-02 16:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (22 votes). Check out past polls.

    Notices?