I tried the options that you have suggested but it seems to work in one case and not in the other.
I want to be able to replace everything from the log directory onwards with certain other paths as I have explained below.
I have a conditional statement in the code where I am saying that if $ver_name is present then replace everything from the log directory onwards with $ver_name/abinitio/run into the variable graph_dir and if $ver_name is not present then replace with abinitio/run into the graph_dir.
I have the following code:
( ! -z $ver_name ) ? (our $graph_dir = $before1) =~s{ /log .* \z}{/$ve +r_name/abinitio/run}xms :(our $grap h_dir=$before2) =~s{ /log/ .* \z}{abinitio/run}xms;
CASE 1:
my $before1 =/home/user/phase/dir1/log/
and when passed through the conditional statement I want to derive the below graph_dir
graph_dir= /home/user/phase/dir1/2.11/ abinitio/run

CASE 2: my $before2 = /home/user/phase/dir1/log/Illinois/
and when passed through the conditional statement I want to derive the below graph_dir
graph_dir =/home/user/phase/dir1/abinitio/run/

In my output when I see Case1 seems to work fine but when in Case 2 the value I am deriving for graph_dir is /home/user/phase/dir1//abinitio/run

Can you please point out where I am going wrong with this?

Thank you.

In reply to Re^4: Manipulating directory paths by pp
in thread Manipulating directory paths by pp

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.