On Thu, Feb 3, 2011 at 4:59 PM, Harry Putnam <rea...@newsguy.com> wrote: > May I ask how that formulation servers the purpose better? Is it > processed more easily or quicker in that formulation as against the > one I posted? > > Or does mine leave too many possibilities for poor results?
Yours just wasn't very precise: > if ( !/^.*\.[bjgtp][gimnps][gfadp]$/) { Instead of specifying valid extensions, you're specifying valid first-characters, valid second-characters, and valid third-characters for the file extension. Pick any random character from each bracket expression (i.e., '[expression]') and you can generate file names that would match and shouldn't. For example: foo.jga bar.ppp baz.gma Obviously not what you intended to match, but they will match (untested). Using a full literal string for the extension means that it needs to match the whole thing exactly. The alternation character (i.e., '|') allows you to specify one of many valid options to choose from. I find it rather luxurious. I know that other regular expression engines seem to only permit first|second whereas Perl seems to allow "any number"[1] of choices, which provides a lot more powerful expressiveness. In addition to the stricter matching rules, it's also rather more easy to read, IMHO. Looking at my regular expression, it should be obvious to any programmer and many computer users that it's matching image file extensions. Yours appears much more random to a human. It might suggest that it's matching file extensions, but it certainly doesn't communicate well which ones it is supposed to match. [1] I don't know if it's actually "unlimited" or not. -- Brandon McCaig <http://www.bamccaig.com/> <bamcc...@gmail.com> V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl. Castopulence Software <http://www.castopulence.org/> <bamcc...@castopulence.org> -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/