in reply to Re^6: Manipulating directory paths
in thread Manipulating directory paths

$ver_name is a parameter that I am passing to this script. And I want the script to execute in one way if the $ver_name is passed and if it is not passed in an another way.

You'd normally check the length of @ARGV (for arguments passed to a script) or @_ (for arguments passed to a function), but defined will do nicely here. defined tells its caller if a variable holds a value other than undef.

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

but instead I am getting /home/user/phase/dir1//abinitio/run

Not with the code and the inputs you provided.
Not with the code I provided and the inputs you provided.

Update:
Changed
if (defined($replace)) {
to
if (defined($ver_name)) {

Replies are listed 'Best First'.
Re^8: Manipulating directory paths
by pp (Novice) on Sep 13, 2007 at 19:28 UTC
    I tried what you suggested but still I a getting the double slashes //.

      There was a typo in the latest version that gave that error. Fixed.

        What typo? Can you point out for me to make the change.

        Thanks.