- 论坛徽章:
- 0
|
- #!/usr/bin/perl
- use 5.018;
- sub search {
- my $file = shift;
- sub {
- my ( $word, %chars, %group ) = shift;
- @chars{ map lc, split //, $word } = ();
- my @chars = keys %chars;
- for my $line (@$file) {
- my @words = $line =~ /\w+/g;
- for my $WORD (@words) {
- my $word = lc $WORD;
- next if $word =~ /[^@chars]/;
- my %check;
- @check{ split //, $word } = ();
- $group{$WORD}++ if keys %check == @chars;
- }
- }
- my @group = keys %group;
- @group ? @group : "[ $word: No Results Found ]";
- }
- }
- my $file = [<DATA>];
- my $google = search $file;
- my @mary = $google->('mary');
- say join ', ', @mary;
- my @lego = $google->('lego');
- say join ', ', @lego;
- __DATA__
- Cat act, python thypoon, thytoon action?
- God said: This Dog is a Good Dog!
- Mary, Larry, Henry, Ramy, Raramy and Rammy army go ray.
- Weith ACT: "white wieth"!
- write "google, lego, gole goel leo loge"...
- Pugool, GOOGLES, geelog, gelleo.
- loogee loople
复制代码 |
|