Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: Comparing string to array elements

by R56 (Sexton)
on Jan 13, 2017 at 15:03 UTC ( [id://1179514]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Comparing string to array elements
in thread Comparing string to array elements

Ok, I was overlooking something. I was comparing a whole set of free text to an array of terms, no wonder why it didn't return anything.

Can the solution be splitting that free text into an array, and then comparing that to the terms I already have, printing the matches?

my @adv = split /\s+/, $1;

How would I compare if each term in @adv matches one on @terms, and then print it if it exists?

Replies are listed 'Best First'.
Re^4: Comparing string to array elements
by hippo (Bishop) on Jan 13, 2017 at 15:34 UTC
Re^4: Comparing string to array elements
by Lotus1 (Vicar) on Jan 13, 2017 at 21:14 UTC

    Why not

    • read in the terms.txt file into a scalar variable using slurp,
    • split that into an array of terms,
    • use a regex inside a foreach loop to test each term against your text?

    The example I gave you was intended to point you in this direction. My example shows how to slurp a file into a scalar variable. Then split that with something like my @terms = split ' ', $terms_text.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-19 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found