in reply to in place editing by variables

cp890:

Are you sure your script is actually failing? It may be doing everything correctly and also emitting those warning lines. Typically I see that sort of error because a blank line (such as the end) in a file has no information on it.

For example:

$ cat t.pl use strict; use warnings; while (<DATA>) { my @f = split /\s+/,$_; $f[1] =~ s/foo/bar/g; print "result: $f[1]\n"; } __DATA__ Poor foolish kitty The empty line above this one might fool us. $ perl t.pl $ perl t.pl result: kitty Use of uninitialized value $f[1] in substitution (s///) at t.pl line 6 +, <DATA> line 2. Use of uninitialized value $f[1] in concatenation (.) or string at t.p +l line 7, <DATA> line 2. result: result: barlish Use of uninitialized value $f[1] in substitution (s///) at t.pl line 6 +, <DATA> line 4. Use of uninitialized value $f[1] in concatenation (.) or string at t.p +l line 7, <DATA> line 4. result:

A simple fix would be to ignore blank lines:

while (<DATA>) { next if /^\s*$/; # skip blank lines ... }

Update: Minor code edit. (Made first case actually substitute.)

...roboticus

When your only tool is a hammer, all problems look like your thumb.