in reply to Identical Arrays
Easy!
A few comments:use Modern::Perl; my @one = ( 1, 2, 3 ); my @two = ( 2, 3, 1 ); my @three = ( 1, 2, 4 ); say identical( \@one, \@two ); # returns 1 say identical( \@one, \@three ); # returns 0 sub identical { my ( $first, $second ) = @_; return ((join chr(0), sort @$first) eq (join chr(0), sort @$second +)) ? 1 : 0; }
- Do not use & to call your subroutines. It is not necessary and has side-effects.
- The parameter list needs references to the arrays, otherwise the subroutine will not be able to distinguish between the two arrays.
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial Deltronics
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Identical Arrays
by philiprbrenan (Monk) on Aug 26, 2012 at 13:26 UTC | |
by CountZero (Bishop) on Aug 26, 2012 at 20:28 UTC |
In Section
Seekers of Perl Wisdom