Applications need a way of knowing if an extention was supplied. For example, it needs to know that to decide whether it should add the default extention.
Not really. In the example you give the application has its own idea of "extension", so all it has to do is:
$filename =~ s/$/$ext/ unless $filename =~ m/$ext$/;
So it's not "does this filename look like it has an extension", but rather, "does this filename look like it has this particular extension" This allows the application to use anything and in no way restricts the characters that can appear in the extension as your second to last paragraph states.
Still, what does it mean to be a filename "extension". I keep using scare-quotes on that word because I've always found it slightly moronic. "The N characters we've allowed you weren't enough? Now you get M more!" It was an efficiency hack that was exposed to the end user and what's more named so that users have a conceptual handle to hang on to the hack. Terrible, terrible, terrible. They should have just stuck with filenames with a larger maximum length.
Anyway, if I were making recommendations as to what to consider an "extension" in general, I'd say it must match /\.[a-zA-Z0-9]+\z/ because that gives a nod to history and another nod to the modern day by not restricting it to 3 characters. (Is .jpeg a valid filename "extension"? :-) But, of course, this only covers 99% of the cases. There will still be strange suffixes used by some applications and that's okay.
In reply to Re^4: AWTDI: Renaming files using regexp
by duff
in thread AWTDI: Renaming files using regexp
by nimdokk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |