Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Found a Perl hole

by shenme (Priest)
on Jan 27, 2005 at 18:14 UTC ( [id://425672]=note: print w/replies, xml ) Need Help??


in reply to Re: Found a Perl hole
in thread Found a Perl hole

You have written quite a lot of code here. It is very confusing to us because of the great number of 'unusual' ways you implement things.

I think it would help you if you would check some of your assumptions on how Perl code works. When in doubt I start up perl in the debug mode and try out a line or two. Such as:

perl -de0 Loading DB routines from perl5db.pl version 1.25 Editor support available. Enter h or `h h' for help, or `perldoc perldebug' for more help. main::(-e:1): 0 DB<1> x chr(127) 0 "\c?" DB<2> x int(chr(127)) 0 0 DB<3> x ord(chr(127)) 0 127
This is me trying out that expression you were confused about. I find out that chr(127) does indeed convert the number into a string character. I then check what int(chr(127)) gives me - zero! Hmmm, doing an int() on a string that doesn't start with a number returns zero. Just to check what bart mentioned I try ord() and see that that is the reverse of what chr() does (which is why he mentioned it).

So I directly tested that part of the problem expression and find out it will _always_ give me zero.

But the array types doesn't always have numbers in it (so that '==' would be appropriate) nor does it always have characters in it (so that 'eq' would be appropriate). Compare these lines:

@types[++$#types] = chr $temp; @types[++$#types] = int(rand(10));
In the first you force the value to be a character, but in the second you ask for the value as an integer. So neither '==' nor 'eq' are going to always work for the values in @types.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-26 04:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found