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
In reply to Re: A way to avoid repeated conditional loops
by Anonymous Monk
in thread A way to avoid repeated conditional loops
by Deus Ex
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |