in reply to Re: Alternative matches
in thread Alternative matches
2) Notice the use of capturing parenthises? It means that kiat wants to know what word he matched. To do that with index gets ugly real fast, for example
Granted you could turn that do{} into a function, but I don't think its worth the effort (even if there may be a slight speed boost).my @words = qw[ new old number start simple cross heavy die exit ]; my $string = q~whatever the NEw old you're trying to match~; my $lcstring = lc $string; my $ret = 0; if( do { for my $val( @words ){ my $r = index $lcstring, $val; if( $r > -1 ){ $ret = substr $string, $r, length $val; last; } } $ret; } ){ warn "the \$1 (aka ret) is => $ret\n\n"; } __END__ the $1 (aka ret) is => NEw
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Alternative matches
by foss_city (Novice) on Oct 06, 2004 at 11:45 UTC | |
by PodMaster (Abbot) on Oct 06, 2004 at 11:57 UTC | |
by Eimi Metamorphoumai (Deacon) on Oct 06, 2004 at 12:48 UTC | |
by PodMaster (Abbot) on Oct 06, 2004 at 13:02 UTC | |
by foss_city (Novice) on Oct 06, 2004 at 12:39 UTC | |
by PodMaster (Abbot) on Oct 06, 2004 at 12:54 UTC | |
|
Re^3: Alternative matches
by Jasper (Chaplain) on Oct 06, 2004 at 12:24 UTC | |
by PodMaster (Abbot) on Oct 06, 2004 at 12:29 UTC |