in reply to Re: How to compare hash value
in thread How to compare hash value

This (simple and easy) method has a tendency to fall down sometimes. If you had 'abc', 'def' in one array, and 'a', 'b', 'c', 'd', 'e', 'f' in another, joining with the empty string will make the strings equal. The simple solution would be to make $" something bizarre, and not likely to appear in the array, like "bcd". Only joking! Maybe ":::", or something.

If you can't be sure of what's in the arrays, comparison of Data::Dumper output of the sorted array might work?

Jasper

Replies are listed 'Best First'.
Re: Re: Re: How to compare hash value
by Ovid (Cardinal) on Apr 23, 2003 at 14:23 UTC

    Whoops! I hadn't thought of that. Nice catch.

    Cheers,
    Ovid

    New address of my CGI Course.
    Silence is Evil (feel free to copy and distribute widely - note copyright text)

Re: Re: Re: How to compare hash value
by nothingmuch (Priest) on Apr 23, 2003 at 14:29 UTC
    To get over that you must encapsulate Sigma, so that a condition like that does not arise. If you convert to a smaller subset and then use out of band data that will be safe (example - convert to hex and join with spaces). Also safe is escaping - because that's basically just creating a wide charset, which is a larger Sigma, enabling data out of the UTF or ASCII sigma. This is possibly faster, and more memory efficient.

    If you join("\\",map { quotemeta($_) } @array); you will get a safe value, because quotemeta ensures that a single \ will never appear in the values.

    -nuffin
    zz zZ Z Z #!perl