monkfan has asked for the wisdom of the Perl Monks concerning the following question:
#!/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 is_subst($super,$sub), "\n"; sub is_subst { my ($super,$sub) = @_; my $sup_len = length $super; my $sub_len = length $sub; foreach (my $i = 0; $i<$sup_len; $i++) { my $str = substr($super,$i,$sub_len); if ( $str eq $sub ) { return 1; last; } } return 0; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Testing if a string is a substring
by davorg (Chancellor) on Jul 20, 2005 at 08:57 UTC | |
|
Re: Testing if a string is a substring
by Zaxo (Archbishop) on Jul 20, 2005 at 09:01 UTC | |
|
Re: Testing if a string is a substring
by gjb (Vicar) on Jul 20, 2005 at 09:01 UTC | |
|
Re: Testing if a string is a substring
by monarch (Priest) on Jul 20, 2005 at 08:50 UTC | |
by reasonablekeith (Deacon) on Jul 20, 2005 at 08:58 UTC |