in reply to Renames files and directories but won't update files at the same time.

I believe this code is much more complex than what it needs to be.

What happens if you turn off the non-greediness in:

        if ( /(.*?)$old_hostname(.*?)/i ) 
          { 
            s/(.*?)$old_hostname(.*?)/$1$new_hostname$2/sgi;
          } 
by saying something like

        if ( /(.*)$old_hostname(.*)/i ) 
          { 
            s/(.*)$old_hostname(.*)/$1$new_hostname$2/sgi;
          }  
 
In this way it will match your prior regexp.

Also, it would have been helpful if you wrote what the output is in the first run of your code.

Also, according to those who know a lot about regexes, saying .* is actually bad as this regexp is very expensive. When you have the time, take a look around the fine Tutorials we have on the monastery. This helped me a lot with the regexes.

Good luck.

  • Comment on Re: Renames files and directories but won't update files at the same time.

Replies are listed 'Best First'.
Re: Re: Renames files and directories but won't update files at the same time.
by Arien (Pilgrim) on Aug 27, 2002 at 12:46 UTC

    The construct

    if (/(CAPTURE BEFORE)REGEX(CAPTURE AFTER)/) { s/(CAPTURE BEFORE)REGEX(CAPTURE AFTER)/$1REPLACEMENT$2/; }

    is better written as a simple

    s/REGEX/REPLACEMENT/;

    — Arien