For the fix to #2,
+ for my $id (@$li_ids) { + push(@{$res->{li_ids}}, $id) + unless grep { $_ == $id } @$needs_importing; + }
I think it will be more efficient if the reference to the result array is cached before entering the for loop:
my $x = $res->{li_ids}; + for my $id (@$li_ids) { + push(@{$x}, $id) + unless grep { $_ == $id } @$needs_importing; + }
Also, the for loop is a generic array operation and so could be packaged as a subroutine:
# Returns the array @$x - @$y sub array_minus { my ($x, $y) = @_; my $z = []; for my $n (@$x) { push @$z, $n unless grep { $_ == $n } @$y; } return $@z; }
To use the sub in the particular context:
- push(@{$res->{li_ids}}, grep { $_ != @$needs_importing } @$li_ids) + push @{$res->{li_ids}}, @{array_minus($li_ids, $needs_importing)};
which makes it a bit more meaningful.
For the fix to #2,
+ for my $id (@$li_ids) { $res->{ li_ids} }, $id)
+ push(@{
+ unless grep { $_ == $id } @$needs_importing;
+ }
I think it will be more efficient if the reference to the result array is cached before entering the for loop:
my $x = $res->{li_ids};
+ for my $id (@$li_ids) {
+ push(@{$x}, $id)
+ unless grep { $_ == $id } @$needs_importing;
+ }
Also, the for loop is a generic array operation and so could be packaged as a subroutine:
# Returns the array @$x - @$y
sub array_minus {
my ($x, $y) = @_;
my $z = [];
for my $n (@$x) {
push @$z, $n unless grep { $_ == $n } @$y;
}
return $@z;
}
To use the sub in the particular context:
- push(@{ $res->{ li_ids} }, grep { $_ != @$needs_importing } @$li_ids) minus($ li_ids, $needs_importing)};
+ push @{$res->{li_ids}}, @{array_
which makes it a bit more meaningful.