Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Array lookup

by Marshall (Canon)
on Apr 17, 2018 at 17:15 UTC ( #1213072=note: print w/replies, xml ) Need Help??


in reply to Array lookup

Your dumper output looked odd to me. Basically you have one row of what would be an Array of Array (AoA). That would have happened if say you initialized these two arrays with square brackets instead of paren's. I'm not sure if that is what you really wanted?

I demo that below and changed to a more usual initialization of a 1D array..

#!usr/bin/perl use strict; use warnings; use Data::Dumper; my @x = [100, 101]; #may not be what you want? print Dumper \@x; my @dead_list = (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); my @get_list = ( '100', '200', '210', '220', '230', '240', '1000', '1001', '1002', '1120', '1210',); sub remove_x99 { my ($deadlist_ref, $getlist_ref) = @_; my %lookup = map{$_=>1}@$getlist_ref; my @result = grep{!exists $lookup{$_}}@$deadlist_ref; return @result; } my @result = remove_x99 (\@dead_list, \@get_list); print "@result\n"; __END__ $VAR1 = [ [ 100, 101 ] ]; 101 103 201 202 203 211 212 221 222 231 232 233 241 242 243 1010 1011 +1012 1020 1021 1022 1121 1122 1211 1212 Note: in the sub if you wanted to modify dead_list: @$deadlist_ref = grep{!exists $lookup{$_}}@$deadlist_ref; would do that.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1213072]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2020-10-25 06:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (249 votes). Check out past polls.

    Notices?