Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Substring comparison

by flaviodesousa (Initiate)
on May 01, 2012 at 15:55 UTC ( [id://968290]=note: print w/replies, xml ) Need Help??


in reply to Re: Substring comparison
in thread Substring comparison

As trammell pointed out index() returns 0 if the sought for string is the beginning. Try this:
@Array1 = qw{XXX FFF ZZZ AAA BBB QQQ LLL JKK III CCC DDD DCD}; @Array2 = ("XXX BBB AAA CCC DDD EEE", "FFF NNN JKK III LLL QQQ"); foreach(@Array1) { $string1 = $_; foreach(@Array2) { my $string2 = $_; my $result = index($string2, $string1); print $string1, ($result >= 0 ? " IS " : " IS NOT", + " found in "), $string2, "\n"; } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-26 09:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found