Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Need help to substitute

by Divakar (Sexton)
on Oct 04, 2012 at 13:21 UTC ( #997230=perlquestion: print w/replies, xml ) Need Help??
Divakar has asked for the wisdom of the Perl Monks concerning the following question:

Hi Folks,

My variable contains below value which has "install_temp" or "install_patch" folder.

i need to change the "install_temp" or "install_patch" folder to "install" like below.

i am not sure how can i make this using regular expressions?

Thank you...

Replies are listed 'Best First'.
Re: Need help to substitute
by 2teez (Priest) on Oct 04, 2012 at 13:40 UTC

    like so:

    use warnings; use strict; while (<DATA>) { chomp; print "before change: ", $_, $/; s/(.+?)install.+?\\(.*?)/$1install\\$2/; print "After change: ", $_, $/; } __DATA__ D:\ostore_7.3.0_tfix_bld\install_temp\OStore\bin\os_coll.adb D:\ostore_7.3.0_tfix_bld\install_patch\osji\lib\osjiload.ldb

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
Re: Need help to substitute
by nemesdani (Friar) on Oct 04, 2012 at 13:29 UTC
    You need to escape the \-s. After that

    =~ s/(install_temp|install_patch)/install/ should work. Or am I missing something?

    I'm too lazy to be proud of being impatient.
Re: Need help to substitute
by Athanasius (Chancellor) on Oct 04, 2012 at 14:49 UTC

    A variation on the theme, using Look-Around Assertions:

    #! perl use v5.12; say s! ( ?<= \\ install ) _ .+? ( ?= \\ ) !!rx for 'D:\ostore_7.3.0_tfix_bld\install_temp\OStore\bin\os_coll.adb' +, 'D:\ostore_7.3.0_tfix_bld\install_patch\osji\lib\osjiload.ldb' +;


    D:\ostore_7.3.0_tfix_bld\install\OStore\bin\os_coll.adb D:\ostore_7.3.0_tfix_bld\install\osji\lib\osjiload.ldb

    Hope that helps,

    Athanasius <°(((><contra mundum

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://997230]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2018-01-21 09:36 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (227 votes). Check out past polls.