in reply to problem with pattern match
until($cust =~ <\w{3,4}>) {
You should get your expected behavior by changing that to:
until($cust =~ /\w{3,4}/) {
since you are trying to match against a regular expression. I'd also add start and end anchors, as your expression as written would also match a 17-letter expression - it contains multiple 3 and 4 letter sets.
until($cust =~ /^\w{3,4}$/) {
As a side note, you can use last to do flow control and reduce your code repetition, as well as use a heredoc:
use strict; use warnings; while (1) { print "Customer abbreviation: "; my $cust = <STDIN>; print "\n"; chomp ($cust); last if $cust =~ /\w{3,4}/; print <<EOT; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!! !!! !!! ABBREVIATION MUST BE 3 OR 4 CHARACTERS !!! !!! !!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! EOT }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: problem with pattern match
by Yary (Pilgrim) on Jun 11, 2010 at 19:05 UTC | |
by jwkrahn (Abbot) on Jun 11, 2010 at 19:25 UTC | |
|
Re^2: problem with pattern match
by space_agent (Acolyte) on Jun 12, 2010 at 17:58 UTC | |
|
Re^2: problem with pattern match
by ddrew78 (Beadle) on Jun 14, 2010 at 12:28 UTC |