in reply to problem with pattern match

I'm not quite sure what is actually implemented there, but the issue appears to be in:

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
    I'm not quite sure what is actually implemented there...

    My guess is that the programmer's directory has 3 files starting with "www" in it. <\w{3,4}> in some shells will match a file that begins with www or wwww. The angle brackets would cause a directory glob, setting $_ to file names matching what's inside once per loop.

    On the other hand, according to "perldoc File::Glob", that pattern should match only files named "w3" or "w4". And even if the shell was interpreting it, it would only match files "www" or "wwww" with nothing following, since it doesn't end with a "*". So I'm a bit at a loss as well.

      Your guess would be wrong.    Whether or not there are matching file names the file glob operator will return the two strings 'w3' and 'w4'.

Re^2: problem with pattern match
by space_agent (Acolyte) on Jun 12, 2010 at 17:58 UTC
    If you want to use non standard delimters "/" you have to do it like this:

     m<PATTERN>

    otherwise you have to stick to :

     /PATTERN/

Re^2: problem with pattern match
by ddrew78 (Beadle) on Jun 14, 2010 at 12:28 UTC
    Thank you, this worked perfectly.