in reply to Re: Reg Expression on file name
in thread Reg Expression on file name
so it's more effective to say:next unless substr($file,0,6) eq 'AB DAT' and substr($file,-4) eq '.doc' ;
A. That's not more effective. It's just as effective. It may be ever so slightly more efficient but the micro-optimization probably isn't really all that important.
B. It's verbose and harder to read at a glance than a simple regular expression is. This is probably more important than whatever small optimization you might get by using substr.
If the filename were in $_ I'd suggest next unless /^AB DAT/ and /\.doc/; which would be a good compromise.
I just noticed your first suggestion:
I think this case in particular would really be a good time to use a literal space instead of \s and avoid /x. In general, I think /x makes short regular expressions harder to read. Do you often use /x on short expressions and if so, what's your reasoning?next unless $file =~ m/^ AB \s DAT .* \.doc $/x;
-sauoq "My two cents aren't worth a dime.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Reg Expression on file name
by fruiture (Curate) on Jan 06, 2003 at 21:03 UTC |