"If $ver_name is present" is meaningless, since I'm pretty sure you don't want to check if the variable exists. I'm guessing from your code that you want to check if the file named by $ver_name exists (which -f would do), but it could mean many other things.

You're using our. Don't use globals.

Don't use the conditional operator (?:) to conditionally execute entire statements. Using that operator for anything but the simplest expression usually makes it unreadable. It really works best when the returned value is actually used.

The output you said you get is not the output the code produces.
It produces '/home/user/phase/dir1abinitio/run'
and not '/home/user/phase/dir1//abinitio/run'
You're missing a / because you removed the / before log without replacing it.
This should have been easy for you to find out by comparing the one that worked and the one that didn't.

my $replace = (-f $ver_name ? "/$ver_name" : '') . '/abinitio/run'; (my $graph_dir = $before) =~ s{ /log/ .* \z }{$replace}xs;

In reply to Re^5: Manipulating directory paths by ikegami
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.