in reply to Re: Check if a word is included in another
in thread Check if a word is included in another

Interesting thought, just need a a little bit tweak:

use warnings; use strict; print check("YLPP", "PEARLYGATES"), "\n"; print check("YLP", "PEARLYGATES"), "\n"; print check("EASYPEASY", "PEARLYGATES"), "\n"; sub check { my ($word, $target) = @_; foreach my $letter (split //, $word) { return "not ok" if ($target =~ s/$letter// == 0); } return "ok"; }

Peter (Guo) Pei

Replies are listed 'Best First'.
Re^3: Check if a word is included in another
by b4swine (Pilgrim) on Apr 18, 2010 at 22:20 UTC
    Isn't this the same as the original algorithm in the first post?

      Not the same, with or without /g makes a big difference in this case.

      use warnings; use strict; my $str1 = "112345"; $str1 =~ s/1//g; print $str1, "\n"; my $str2 = "112345"; $str2 =~ s/1//; print $str2, "\n";

      Peter (Guo) Pei

        I mean the original original post, where the question was first asked by me. There are no s///g in that post.