in reply to Re: terrible code about array matching...
in thread terrible code about array matching...

That's a bit dangerous isn't it?

#!/usr/bin/perl use strict; use warnings; my @car = ('a', 'b,c'); my @cond = ('a', 'b', 'c'); if(join(',', @car) eq join(',', @cond)) { print "FOUND\n"; } else { print "NOT FOUND\n"; }

This indicates that the arrays are the same even tho', clearly, they aren't.

If you're going to use code like this you have to know what are valid characters in your input arrays and be very careful in choosing your join string.

--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re: Re: Re: terrible code about array matching...
by grantm (Parson) on Nov 06, 2002 at 20:52 UTC
    That's a bit dangerous isn't it?

    In general yes, it is dangerous and as you suggest it's important to chose a separator that you knew could not occur in the data.

    In the specific case of my suggestion, (which possibly wasn't clear) I was assuming the arrays had been populated by the original posters' code which validated each argument before pushing onto the array. I was merely proposing to replace the loop which compared the arrays.

    The other problem with my code as a general solution is that it doesn't scale well. Once again though, in the context of what the poster was trying to do I think it's reasonable.