{"id":8827,"date":"2012-12-18T01:05:14","date_gmt":"2012-12-18T07:05:14","guid":{"rendered":"http:\/\/bucktownbell.com\/?p=8827"},"modified":"2012-12-20T12:24:03","modified_gmt":"2012-12-20T18:24:03","slug":"how-to-find-out-if-x-is-an-element-in-an-array","status":"publish","type":"post","link":"http:\/\/bucktownbell.com\/?p=8827","title":{"rendered":"How to find out if X is an element in an array?"},"content":{"rendered":"<blockquote><p>Try using the modern <a href=\"http:\/\/perldoc.perl.org\/perlop.html#Smartmatch-Operator\">&#8220;smart match&#8221; operator<\/a>:<br \/>\n<code>if ( $tofind ~~ @in )<\/code><\/p><\/blockquote>\n<p>via <a href=\"http:\/\/www.perlmonks.org\/?node_id=2482\">How to find out if X is an element in an array?<\/a>.<\/p>\n<p>Had to do this for a script I&#8217;m writing where I need to compare two lists and find out which elements in list A aren&#8217;t in list B.\u00a0\u00a0 This was the simplest of all the solutions described in the above link.\u00a0 I haven&#8217;t actually implemented this yet&#8230;<\/p>\n<p><strong>Update 12\/19<\/strong>.\u00a0 The above does indeed work.\u00a0 Not sure how they do it.\u00a0 It would seem comparing two lists of length <em>n <\/em>would be an O(n**2) problem.\u00a0 Might have to look into a proper database however it&#8217;s still manageable at this scale.<\/p>\n<p>Also, a shoutout to perlmonks.org, a site that usually gets high rankings on my searches for perl related information and that is always concise and easy to read to\u00a0 divine the info I was searching for.\u00a0 The above link is a perfect example.\u00a0 It points to a page that contains a lot of different implementations of what is probably a very common algorithmic problem.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Try using the modern &#8220;smart match&#8221; operator: if ( $tofind ~~ @in ) via How to find out if X is an element in an array?. Had to do this for a script I&#8217;m writing where I need to compare &hellip; <a href=\"http:\/\/bucktownbell.com\/?p=8827\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54],"tags":[171],"class_list":["post-8827","post","type-post","status-publish","format-standard","hentry","category-programming","tag-perl"],"_links":{"self":[{"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/posts\/8827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8827"}],"version-history":[{"count":6,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/posts\/8827\/revisions"}],"predecessor-version":[{"id":8851,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/posts\/8827\/revisions\/8851"}],"wp:attachment":[{"href":"http:\/\/bucktownbell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8827"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}