Your "check_same" sub is written to use just two array refs as args, but you are calling it with a long list of arrays (not refs to arrays). The two calls you have to check_same should look like this:
Apart from that, you should probably make your sub definition simpler (skip the "(\@\@)" part), but check to make sure the args are refs to arrays:print "\@D is not the same as \@E\n" unless check_same( \@D, \@E ); print "\@D is the same as \@F\n" if check_same( \@D, \@F );
You might also consider the "carp" or "croak" methods provided in Carp, instead of "die", to handle those kinds of error conditions in a subroutine.sub check_same { my ( $ref1, $ref2 ) = @_; die "Bad args passed to check_array\n" unless ( ref( $ref1 ) eq 'ARRAY' and ref( $ref2 ) eq 'ARRAY' ) +; return 0 if @$ref1 != @$ref2; for my $i ( 0 .. $#$ref1 ) { return 0 if $$ref1[$i] ne $$ref2[$i]; } return 1; }
In reply to Re: compare and output to the screen
by graff
in thread compare and output to the screen
by coronalvrr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |