in reply to A way to avoid repeated conditional loops
Use m?alpha? instead of m/alpha/ to match only once:
#!/usr/bin/perl use warnings; use strict; while (<DATA>) { if (m?alpha?) { print "+ $_"; } else { print "- $_"; } } __DATA__ beta beta alpha beta beta alpha alpha beta
Results in:
- beta - beta + alpha - beta - beta - alpha - alpha - beta
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A way to avoid repeated conditional loops
by Deus Ex (Scribe) on Aug 25, 2011 at 13:13 UTC | |
by pvaldes (Chaplain) on Aug 26, 2011 at 00:45 UTC |