For one thing, the "s/.../.../" as written there is applying to $_, not to $line, which is where I think you want it to apply.s/$1//g if ($line =~ m/.*(\[.*\])\s.*/); s/$1/ /g if ($line =~ m/^\w.*(\s\s).*/);
It would be better to write these as:
There are more verbose, "less optimized" ways that might look less obscure (hence be worth the extra keystrokes or cpu cycles) -- e.g.:$line =~ s/\[[^]]+\]//g; $line =~ s/\s+(?=\S)/ /g;
(update: had to add the "g" modifiers on those substitutions)$line =~ s/ \[ .*? \] //gx; # remove strings enclosed by "[..]" $line =~ s/ \s+ (\S) / $1/gx; # normalize line-internal whitespace
Please refer to "perldoc perlre" for anything in those examples that you don't understand. (Hint: the "(?=...)" is referred to as a "zero-width look-ahead assertion".)
In any case, the message you're getting isn't really an "error" -- it is a "warning", provided to you because you asked to get warnings, and because it describes a situation where you might want to double check to see whether it really matters that an uninitialized value is being used in a particular operation on a given line in your code.
(There are cases where it's actually okay to use uninitialized values in places that trigger warnings -- but it usually doesn't hurt much to have perl draw your attention to such cases, especially during development.)
What really matters is whether the output is what you want it to be. Is it?
In reply to Re: combining elements of arrays
by graff
in thread combining elements of arrays
by tcf03
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |