Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

i am having a line in text file
i read that file in perl script and have to change that line for example
if (-e "test2122.asm")
i have to change it to
if (-e "../test2122.asm")
i tried using =~ tr and s| but was nor successful. how this can be done using perl script.

Replies are listed 'Best First'.
Re: string substitution
by GrandFather (Saint) on Feb 23, 2006 at 11:35 UTC

    This uses a look behind ((?<=")) to match the " and a \b to make sure the " is followed by a "word" character.

    use warnings; use strict; while (<DATA>) { s/(?<=")\b/..\//; print; } __DATA__ if (-e "test2122.asm")

    Prints:

    if (-e "../test2122.asm")

    DWIM is Perl's answer to Gödel