in reply to A C-like brain in a Perl-like world
This won't work. All arguments will go into @array1, and @array2 will be empty. You need to pass in array references if you want to preserve which argument is which (although the way your loop functions, it sort of doesn't matter). In fact, it looks like you are mixing up your array names with your scalar names in the merge function. Maybe you need to use strict and warnings??sub merge { my (@array1,@array2) = @_;
Besides, the subroutine can be done more simply as:
sub merge { my %hash; @hash{@_} = (); sort keys %hash; } my @array1 = qw(a b c d e); my @array2 = qw(c d e f g); my @merged = merge(@array1, @array2); print "@merged\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: A C-like brain in a Perl-like world
by Aristotle (Chancellor) on Sep 27, 2001 at 13:30 UTC | |
by runrig (Abbot) on Jun 06, 2005 at 23:57 UTC | |
by Aristotle (Chancellor) on Jun 09, 2005 at 01:43 UTC |