http://www.perlmonks.org?node_id=182553

Sara has asked for the wisdom of the Perl Monks concerning the following question:

Hello guys ,, if I have this
```\nb\hot\src\hot2.cpp@@\main\gold\4
I want to use this command called cleardiff for that path as follow:
```cleardiff \nb\hot\src\hot2.cpp@@\main\gold\3 \nb\hot\src\hot2.cpp@@\ma
+in\gold\4
so what I ma doing is getting the whole line and subtracting the last number by 1 then calling cleardiff for the two path in one command line. I am not sure how to get to the last value .. split doesn't seem to be a solution ,, also =~ s/\.gold\d/\gold\d+1/ not working ,, any easir way .. thanks for help

Replies are listed 'Best First'.
Re: change the end of a path inside file
by jwest (Friar) on Jul 17, 2002 at 19:13 UTC
use File::Spec.

The splitpath method will seperate the file name from the directory. Take the file it returns, decrement it, and use the catpath method to rebuild the path.

This solution will be portable across most systems.

```
use File::Spec;

my (\$volume, \$path, \$file) = File::Spec->catpath(\$path_to_decrement);

--\$file;

my \$newpath = File::Spec->catpath(\$volume, \$path, \$file);

This way is a little pedestrian, but it gets the job done.

Hope this helps!

--jwest

```-><- -><- -><- -><- -><-
All things are Perfect
To every last Flaw
And bound in accord
With Eris's Law
- HBT; The Book of Advice, 1:7
```
Re: change the end of a path inside file
by ichimunki (Priest) on Jul 17, 2002 at 19:10 UTC
```sub dec {return(shift)-1};
\$path =~ s/(\d+)\$/dec(\$1)/e;