develooper Front page | perl.beginners | Postings from February 2002

regexp for validating DOS 8.3 filename

Thread Next
From:
jpf
Date:
February 12, 2002 09:43
Subject:
regexp for validating DOS 8.3 filename
Message ID:
12518356465.20020212124235@laserprintplus.com
I'm sure this is simple but I'm getting more and more confused:
I want to validate input so that it is either:
   a valid dos filename (we still use it)
   up to 12 alphanumeric characters (inc spaces)
   nothing (in which case 'none' would be entered by default

Here's my snippet:
#!/usr/bin/perl
use strict;
my $file;
print "\nType filename [8.3] or [enter] for none: ";
while (<STDIN>){
        chomp;
        # last if ((/^\S{1,8}\.\S{0,3}/)or(/^\w{1,12}/));
        last if (/\w{1,12}/);
        print "try again: "
}
print "approved";

Testing the above I realised that (/\w{1,12}) was allowing more than
12 alphanumeric characters (I've commented out the first
'last if' to test on it's own) and I'm not sure why. I've been stuck
on this for a considerable time so I'd really appreciate someone's
insight into my errors.


(DOS regexp was supplied by 'Steve Litt's PERLs of Wisdom')

-- 


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About