in reply to Escaping confusion in RE...

What makes you think there is an infinite loop? BTW, you only have one backslash before 'Data' on the RHS in your example. Other than that, you seem to have it correct, by just doubling up on all the backslashes.

Replies are listed 'Best First'.
Re^2: Escaping confusion in RE...
by freddo411 (Chaplain) on Jul 05, 2007 at 22:36 UTC
    I didn't give enough context. My bad. The substitution does seem to work. Here's more context, and the error.
    while ( @file ) { s#l:\\Data\\([0-9]*)\\#D:\\Sites\\$1\\Data\\#i; print; }
    @file is filled with many lines like so: my @file = <FILE>;

    Here are the warnings:
    Use of uninitialized value in print at foo.pl line 44. Use of uninitialized value in substitution (s///) at foo.pl line 43. Use of uninitialized value in substitution (s///) at foo.pl line 43.

    -------------------------------------
    Nothing is too wonderful to be true
    -- Michael Faraday

      If @file is an array then you want a for loop, not a while loop. If you want to read lines from a file into $_ then you want while ( <FILE> ) {

      I.e., you do have an infinite loop, @file has a constant number of things in it, so it is always true, unless you shift or pop things from it in the loop. (but a for loop is probably more appropriate).

      ([0-9]*) will match zero or more digits.

      To be a little cleaner, you probably should match 1 or more digits using ([0-9]+)