Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Matching multiple substrings of a string to arrays and printing those that match

by toolic (Bishop)
on Apr 03, 2018 at 19:46 UTC ( #1212285=note: print w/replies, xml ) Need Help??


in reply to Matching multiple substrings of a string to arrays and printing those that match

Your dis and apr arrays only have one element each in them, corresponding to the last line of each file. You should push into each array. For example, change:
@dis_dic = $f1_line;

to:

push @dis_dic, $f1_line;

Also, your use of index looks strange. Re-read the docs. You could use grep there. But, I think using hashes is better than arrays in this case.

Replies are listed 'Best First'.
Re^2: Matching multiple substrings of a string to arrays and printing those that match
by mr_ron (Hermit) on Apr 03, 2018 at 21:24 UTC

    For reading the arrays of verbs one might also do something like:

    my @dis_dic; open(my $in1, "<", "$dis_verbs") or die "error reading $dis_verbs. $!"; chomp(@dis_dic = <$in1>); close($in1);

    Besides needing grep or List::Util qw(any) to test index for an array of substrings, I am confused by the logic/specification of:

    elsif ( index($f3_line, @apr_dic && @dis_dic) != -1 ) {

    I am not sure whether the intent is to test for both approved and discarded verbs or either one. There is no point testing for the 'both' case since we already printed for approved and similarly if looking for either I think we just need to grep/any discarded. Do you need discarded verbs removed from the matching lines as in choroba's post?

    Ron

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2020-10-24 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (246 votes). Check out past polls.

    Notices?