Leaving aside other issues that this script might have, the immediate, short answer to your question is that you don't want statements like this:
s/$1//g if ($line =~ m/.*(\[.*\])\s.*/); s/$1/ /g if ($line =~ m/^\w.*(\s\s).*/);
For one thing, the "s/.../.../" as written there is applying to $_, not to $line, which is where I think you want it to apply.

It would be better to write these as:

$line =~ s/\[[^]]+\]//g; $line =~ s/\s+(?=\S)/ /g;
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/ \[ .*? \] //gx; # remove strings enclosed by "[..]" $line =~ s/ \s+ (\S) / $1/gx; # normalize line-internal whitespace
(update: had to add the "g" modifiers on those substitutions)

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.