in reply to Found a Perl hole

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re^2: Found a Perl hole
by bart (Canon) on Jan 27, 2005 at 17:20 UTC
    == is for numbers only, use eq for string comparison. Oh, and please use $ not @ if you want to work with one array item as a scalar.

    Summary:

    if(chr(127) eq $types[$t])

    But, what's that int doing there in your code? A perl character is a string, not a number. I bet you're thinking of the functionality offered by ord. But ord(chr(127)) is nonsense, that's just 127.

Re^2: Found a Perl hole
by kutsu (Priest) on Jan 27, 2005 at 17:22 UTC

    I think you mean if(int(chr(127)) == $types[$t]...to second davis:

    use warnings; use diagnostics; if(int(chr(127)) == @types[$t]) { print "BOO!\n"; }

    Gives (among other interesting but pointless for this demo):

    Scalar value @types[$t] better written as $types[$t] at test.pl line 4 (#2) (W syntax) You've used an array slice (indicated by @) to select a single element of an array. Generally it's better to ask for a scalar value (indicated by $). The difference is that $foo[&bar] always behaves like a scalar, both when assigning to it and when evaluating its argument, while @foo[&bar] behaves like a list when you assign to it, and provides a list context to its subscript, which can do weird things if you're expecting only one subscript.

    "Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce