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

Re: Looking for N/A twice

by Cody Pendant (Prior)
on Oct 22, 2007 at 04:59 UTC ( [id://646362]=note: print w/replies, xml ) Need Help??


in reply to Looking for N/A twice

Off-topic, but I realised that you could search for two or more occurrences of a substring in a string with nested index() calls like this:
$str = 'N/A N/A blah blah blah SATA N/A blah blah N/A'; $substr = 'N/A'; if (index($str,$substr, index($str,$substr)+1 ) ) { print "two or more occurrences of '$substr' in '$str'" }
which is probably way faster than any RegEx method.


Nobody says perl looks like line-noise any more
kids today don't know what line-noise IS ...

Replies are listed 'Best First'.
Re^2: Looking for N/A twice
by ambrus (Abbot) on Oct 22, 2007 at 09:07 UTC

    No way. index($str,$substr, index($str,$substr)+1 practically always returns true, even if $str has $substr only once or not at all. I don't think it's way faster than regexen either.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (None)
    As of 2024-04-25 01:05 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found