Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi everybody. Being relatively new to perl is am still having problems applying what I know to my needs. How do I impose a condition in an if cicle for matching the first word of a string part of an @AoA data structure with the first word of a string in another array? My goal is then to add the second word of the first string to the second string. Thank you all very much in advance

my($other_array) = ''; foreach $other_array (@other_array){ foreach my$arr (@AoA){ foreach my$sca (@$arr){ $sca if (($sca =~ m/\w+/g)[0] eq ($uniq_kmers =~ m/\w+/g)[0]){ $uniq_kmers =~ "\t".($sca =~ m/\w+/g)[1]; }else{ $uniq_kmers =~ "\t0"; } } } }

Replies are listed 'Best First'.
Re: pattern matching from an array to an array of arrays
by Corion (Patriarch) on Oct 22, 2016 at 11:54 UTC

    See First word, which has a similar problem. Maybe you can adapt the answers given there to your problem?

      Yes, thanks. Actually I started from there, the only thing that bugs me is that I am not at all sure if the condition in the if cycle is appropriate. I've looked up on the internet but I can't seem to get a grip on it.

        So, how does your if condition work currently, and what do you want it to do instead?

        Please help us help you better and supply a short, self-contained example that reproduces the problem you encounter. That way, we can more easily see the situation you are in and guide you better to a solution.

        In your case, please add fake input data that makes your problem happen and also describe what should happen instead. Also add enough scaffolding around the code you currently have to declare and initialize all variables.