Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Escaping confusion in RE...

by freddo411 (Chaplain)
on Jul 05, 2007 at 22:36 UTC ( [id://625145]=note: print w/replies, xml ) Need Help??


in reply to Re: Escaping confusion in RE...
in thread Escaping confusion in RE...

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

Replies are listed 'Best First'.
Re^3: Escaping confusion in RE...
by runrig (Abbot) on Jul 05, 2007 at 22:40 UTC
    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).

Re^3:Escaping confusion in RE...
by toolic (Bishop) on Jul 06, 2007 at 00:36 UTC
    ([0-9]*) will match zero or more digits.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://625145]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-20 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found