in reply to Re: Removing File Extensions
in thread Removing File Extensions
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re^2: Removing File Extensions
by dragonchild (Archbishop) on May 02, 2004 at 02:49 UTC | |
by tkil (Monk) on May 02, 2004 at 03:09 UTC | |
by dragonchild (Archbishop) on May 02, 2004 at 15:54 UTC | |
by tkil (Monk) on May 02, 2004 at 18:29 UTC | |
by dragonchild (Archbishop) on May 02, 2004 at 19:10 UTC |