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 08: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.