in reply to Check if a word is included in another

sub wordCheck{ my $s = join '', sort split'', $_[0]; my $re = join'.*', sort split'', $_[1]; return $s =~ $re; }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

Replies are listed 'Best First'.
Re^2: Check if a word is included in another
by b4swine (Pilgrim) on Apr 18, 2010 at 22:23 UTC
    This is not counting the number of times a letter appears.

      Did you try it?

      print wordCheck( 'onlyones', $_ ) for qw[ none noon noone lyoness ]; 1 1 1

      Perhaps this will clarify:

      sub wordCheck{ my $s = join '', sort split'', $_[0]; my $re = join'.*', sort split'', $_[1]; print "doing: $s =~ $re"; return $s =~ $re; } print wordCheck( 'onlyones', $_ ) for qw[ none noon noone lyoness ];; doing: elnnoosy =~ e.*n.*n.*o 1 doing: elnnoosy =~ n.*n.*o.*o 1 doing: elnnoosy =~ e.*n.*n.*o.*o 1 doing: elnnoosy =~ e.*l.*n.*o.*s.*s.*y
        I did, but made the mistake of swapping the target and the word, so that the results came out wrong. Sorry for the complaint. Otherwise this is really very pretty. Of course credit also goes to jwkrahn for starting this thread.