Try this one:
#!/usr/bin/perl use strict; use warnings; my $target = 'PEARLYGATES'; for my $word ( qw( EASYPEASY GATES PERL ) ){ if( check_word( $target, $word ) ){ print "$target contains $word\n"; }else{ print "$target does not contain $word\n"; } } sub check_word { my $target = shift @_; my $word = shift @_; my @target = sort split //, uc $target; my @word = sort split //, uc $word; my $tidx = 0; for my $char ( @word ){ while( $char gt $target[$tidx] ){ $tidx ++; return 0 if $tidx >= @target; } if( $char eq $target[$tidx] ){ $tidx ++; }else{ return 0; } } return 1; }
In reply to Re: Check if a word is included in another
by shawnhcorey
in thread Check if a word is included in another
by b4swine
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |