bartrad has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, I'm trying to create a new array called @result that contains the elements of @dead_list without those that also appear in @get_list.
@dead_list
$VAR1 = [ [ 100, 101, 103, 200, 201, 202, 203, 210, 211, 212, 220, 221, 222, 230, 231, 232, 233, 240, 241, 242, 243, 1000, 1001, 1002, 1010, 1011, 1012, 1020, 1021, 1022, 1120, 1121, 1122, 1210, 1211, 1212 ] ];
@get_list
$VAR1 = [ [ '100', '200', '210', '220', '230', '240', '1000', '1001', '1002', '1120', '1210' ] ];
Here's the code I'm using:
sub remove_x99 { my @dead_list = shift; my @get_list = shift; ###REMOVE TARGET X99 ENTRIES FROM DEAD_lIST print Dumper\@dead_list; print Dumper\@get_list; my %lookup; my @result; @lookup{@get_list} = (); print Dumper \%lookup; foreach my $elem (@dead_list) { push(@result, $elem) unless exists $lookup{$elem}; } print Dumper\@result; }
And here's what the Dumper of %lookup looks like:
$VAR1 = { 'ARRAY(0x1a56440)' => undef };
I'm completely baffled as @results just returns the exact same thing as @dead_list... can anyone help please?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array lookup
by SuicideJunkie (Vicar) on Apr 16, 2018 at 20:56 UTC | |
|
Re: Array lookup
by 1nickt (Canon) on Apr 17, 2018 at 00:48 UTC | |
|
Re: Array lookup
by Laurent_R (Canon) on Apr 17, 2018 at 06:31 UTC | |
by karlgoethebier (Abbot) on Apr 17, 2018 at 10:09 UTC | |
by Laurent_R (Canon) on Apr 17, 2018 at 17:01 UTC | |
by karlgoethebier (Abbot) on Apr 17, 2018 at 17:37 UTC | |
|
Re: Array lookup
by Marshall (Canon) on Apr 17, 2018 at 17:15 UTC | |
|
Re: Array lookup
by dorko (Prior) on Apr 17, 2018 at 18:03 UTC |