in reply to matching a regular expression
You can use index to good effect like this:
use strict; use warnings; my $state; my $firstAttempt = 1; while (1) { if($firstAttempt) { $state = promptUser("What network to listen for SNMP traps [hs +bn or admin]? ", "admin"); ; $firstAttempt = 0; } else { $state = lc promptUser("ERROR: $state Invalid Re-enter the net +work"); } if (0 == index 'hsbn', $state) { $state = 'hsbn'; last; } elsif (0 == index 'admin', $state) { $state = 'admin'; last; } } if ($state eq 'hsbn') { #some action }
Note that if you need to disambiguate between two strings that match for the first few characters you can require some number of characters thus:
if (0 == index 'hsbn', $state and length ($state) >= 2) {
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: matching a regular expression
by blazar (Canon) on May 18, 2006 at 10:57 UTC |