in reply to How can I get rid of the full stop using fileparse and regex?
join $req_file, $dir, $ext
As the documentation says:
You are guaranteed that $dirs . $filename . $suffix will denote the same location as the original $path.If you want to remove the dot, you don't need to know the length of the string:
#! /usr/bin/perl use warnings; use strict; use File::Basename; for my $row('./filename.ext', '../filename', 'filename.s1.s2') { my ($filename, $dirs, $suffix) = fileparse($row, qr/\..*/); substr $suffix, 0, 1, q(); # Remove the dot. print "$_\t" for $filename, $dirs, $suffix; print "\n"; }
Update: Fixed to handle various suffixes. Change the regex to qr/\.[^.]*/ if you only want s2 as the suffix of filename.s1.s2.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How can I get rid of the full stop using fileparse and regex?
by emmalg (Initiate) on Mar 24, 2015 at 15:26 UTC |