How can I modify the directory in a Perl string that has a file path?

Posted by imerez on Stack Overflow See other posts from Stack Overflow or by imerez
Published on 2010-05-14T13:13:26Z Indexed on 2010/05/14 23:14 UTC
Read the original article Hit count: 218

Filed under:
|

I have a string that has a file path:

$workingFile = '/var/tmp/A/B/filename.log.timestamps.etc';

I want to change the directory path, using two variables to note the old path portion and the new path portion:

$dir = '/var/tmp';
$newDir = '/users/asdf';

I'd like to get the following:

'/users/asdf/A/B/filename.log.timestamps.etc'

© Stack Overflow or respective owner

Related posts about perl

Related posts about string-manipulation