I applaud your use of a prepackaged module, but I personally think it's a bit overkill in this situation.
my @files = qw( foo.zip twotwo.doc three.one.four.ppt four ); my ( @only_names, @only_exts ); foreach ( @files ) { if ( m/^ (.*?) (?:\.([^.]+))? $/x ) { push @only_names, $1; push @only_exts, $2; # might be undef } else { warn "couldn't parse '$!'"; } } # only for debugging output foreach ( @only_exts ) { $_ = 'undef' unless defined $_ } print "names = [ @only_names ]\n", "exts = [ @only_exts ]\n";
Which produced:
names = [ foo twotwo three.one.four four ] exts = [ zip doc ppt undef ]
I guess I feel that, since your solution even with a standard module also requires crafting a regex, I'd just as soon write a regex for the whole thing. *shrug*
My main concerns with my solution would be whether the regex is efficient enough — the non-greedy filename part worries me a bit — and the usual "well, you might be able to craft such a regex, but the average programmer..." complaints.
In reply to Re^2: Removing File Extensions
by tkil
in thread Removing File Extensions
by BalochDude
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |