in reply to Matching arrays with different number of elements and element size

Hi, try the function all in the core module List::Util.

use strict; use warnings; use feature 'say'; use List::Util 'any'; my @wanted = ( 'foo', 'bar', 'baz', 'missing' ); my @source = ( 'foo 42', '666 bar', 'baz (qux)' ); for my $wanted ( @wanted ) { if ( any { /$wanted/ } @source ) { say "Found $wanted"; } else { say "Cannot find $wanted"; } }
Output:
$ perl 1195036.pl Found foo Found bar Found baz Cannot find missing


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Matching arrays with different number of elements and element size
by Ksonar (Initiate) on Jul 14, 2017 at 04:37 UTC

    Hi 1nickt,

    thanks for the help. I have a different dataset on which I am trying this on but I am not getting what I wanted but I will modify this and use it.