Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

change the end of a path inside file

by Sara (Acolyte)
on Jul 17, 2002 at 18:50 UTC ( #182553=perlquestion: print w/replies, xml ) Need Help??

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

Hello guys ,, if I have this
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!


    -><- -><- -><- -><- -><-
    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;
    will change path the way you want, be sure to copy the value before doing this so your system call has access to both values. You may also want to check for success, in case filenames do not end in digits.

    thanks to ferrency for the /e tip.

      thank you all ,, ;) nice one

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://182553]
Approved by ichimunki
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2020-01-18 06:45 GMT
Find Nodes?
    Voting Booth?