emmalg has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I have been trying to insert some file information (filename and type) into a DB and thought the fileparse function was ideal.
I'm using simple filenames, 59 alphanumeric and _ chars, the dot and a three or two char alphanumeric extension.
my $row = ./filename.ext; ($req_file, $dir, $ext) = fileparse($row, '(?<=\.)[^.]*');
As described in the manual the regexp splits off the suffix. I don't want the dot in the suffix but because of how fileparse works, when I use this regexp, I get the dot at the end of the filename. I don't want it there either! :)
I have spent my entire morning reading the regexp info on perldoc.org and haven't seen anything to help. Is there a regular expression that I can use to get both $req_file and $ext without the dot?
For now I am just running $req_file through substr as it is a known length.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How can I get rid of the full stop using fileparse and regex?
by choroba (Cardinal) on Mar 24, 2015 at 15:06 UTC | |
by emmalg (Initiate) on Mar 24, 2015 at 15:26 UTC | |
|
Re: How can I get rid of the full stop using fileparse and regex?
by graff (Chancellor) on Mar 25, 2015 at 01:33 UTC |