Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Re: Comparing arrays

by Arien (Pilgrim)
on Dec 24, 2002 at 09:32 UTC ( [id://222076]=note: print w/replies, xml ) Need Help??


in reply to Re: Comparing arrays
in thread Comparing arrays

That doesn't necessarily work as intended if the values of one or more elements in either array contain the list separator $":

my @array1 = qw(one two three); my @array2 = ("one" . $" . "two", "three"); if ("@array1" eq "@array2") { print 'They are the same', $/; # no, they are NOT }

The updated code is still flawed, consider:

my @array1 = qw(one two three); my @array2 = qw(onetwo three); if ( do{ local $" = ''; "@array1" eq "@array2"} ) { print 'They are the same', $/; # no, they are NOT }

This second update still isn't the way to do it... I took out the local $" (which should be no problem as the value of $" shouldn't matter anyway). Consider:

my @array1 = ("one", "two" . $" . "three"); my @array2 = ("one" . $" . "two", "three"); if ( do{ @array1 == @array2 and "@array1" eq "@array2"} ) { print 'They are the same', $/; # no, they are NOT }

Stringifying would only work if it is guaranteed that $" doesn't occur as a substring of one or more values of either array.

— Arien

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2025-01-14 05:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (38 votes). Check out past polls.