There is a CPAN module Set::Array . I know it may be a little painful
to learn and CPAN modules for such a small application but in the long
run It helps especially if you are repititively going to use these functions
Priss wrote:
> Hello,
>
> I am very new to Perl, wonder if someone can help m
@h{@arr1}=();
delete @h{@arr2};
print join("\n",keys %h),"\n";
david
Priss wrote:
> Hello,
>
> I am very new to Perl, wonder if someone can help me
> with this... if I have:
>
> @arr1 = qw (one two three four five);
> @arr2 = qw (two four);
>
> How can I remove all elements from @arr2 from @
>use hashes.
>my %HASH;
>$HASH{$_}++ foreach @arr1;
>delete $HASH{$_} foreach @arr2;
>@arr1 = keys %HASH;
> @arr1 now has ( one three five );
Perhaps If you want to maintain the order in the array, you might use it this way:
my %HASH;
my %hORD;
my $count = 0;
$HASH{$_} = ($count++) for @arr1
See inline comment:
> -Original Message-
> From: Nikola Janceski [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 21, 2002 8:58 AM
> To: 'Priss'; [EMAIL PROTECTED]
> Subject: RE: Remove elements in an array from a different array
>
>
>
On Wed, 21 Aug 2002, Priss wrote:
> Hello,
>
> I am very new to Perl, wonder if someone can help me
> with this... if I have:
>
> @arr1 = qw (one two three four five);
> @arr2 = qw (two four);
This is a faq, perldoc -q intersection
Although for this kind of operations a hash might be better op
use hashes.
my %HASH;
$HASH{$_}++ foreach @arr1;
delete $HASH{$_} foreach @arr2;
@arr1 = keys %HASH;
@arr1 now has ( one three five );
> -Original Message-
> From: Priss [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 21, 2002 8:54 AM
> To: [EMAIL PROTECTED]
> Subject: Remove elem