Just like poolpi said, File::Spec is the way to go. Substituting a directory segment of a path can be annoying, because paths tend to be specified in different formats. For example: File::Find under windows returns the results with a slash appended, even though the path was specified using backslashes. In such cases you have a mixed syntax of slashes and backslashes. If you use File::Spec, you won't have to worry about the specific syntax of a path. Example:
use File::Spec; # Example with mixed syntax my $old_dir = "D:\\Windows\\programs1"; my $new_dir = "D:\\Windows/programs2"; my $old_fn = "D:/Windows/programs1/a.txt"; my $rel_path = File::Spec->abs2rel($old_fn, $old_dir); my $new_fn = File::Spec->catfile($new_dir , $rel_path); print "New Filename: $new_fn\n"; # or combine both: my $new_fn2 = File::Spec->catfile($new_dir , File::Spec->abs2rel($old_ +fn, $old_dir)); print "New Filename2: $new_fn2\n";

In reply to Re: problem in substitution by rminner
in thread problem in substitution by azaria

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.