Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Testing if a string is a substring

by monarch (Priest)
on Jul 20, 2005 at 04:50 UTC ( [id://476425]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Testing if a string is a substring

#!/usr/bin/perl -w use strict; my $super = 'AAAAATT'; my $sub = 'AT'; # Returns 1 (True) #my $sub = 'AAA'; # Returns 1 (True) #my $sub = 'GGG'; # Returns 0 (False) print "1\n" if ( $super =~ m/\Q$sub\E/ );

Replies are listed 'Best First'.
Re^2: Testing if a string is a substring
by reasonablekeith (Deacon) on Jul 20, 2005 at 04:58 UTC
    I wouldn't use a regex for this, there aren't any patterns, just plain old string matching
    my $super = 'AAAAATT'; my $sub = 'AT'; print "1\n" if (index($super, $sub) != -1);
    ---
    my name's not Keith, and I'm not reasonable.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://476425]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.