in reply to How can I get rid of the full stop using fileparse and regex?

The dot must go somewhere (the file name or the suffix), so you can roundtrip the original path back with
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

    I actually did exactly that with my substr right after writing my post. Apparently I am having a day where I want to do everything the difficult way! I need someone to shout KISS at me.

    Thanks for responding to what was a bit of a daft question. Now at least I understand why the fileparse function works the way it does.