Quick fix:

my $Person1 = defined($1) ? $1 : ''; my $Person2 = defined($2) ? $2 : '';

But that's just covering the problem, assuming your data always has two persons in each 'Pairing Start' line. A better solution would be to re-write the regex in line 17: It's very greedy, and is probably grabbing more than you intend in several places.

First off, drop the last '.*'. You aren't saving it, and you haven't anchored the regex on that end, so it's not doing anything except eat processor cycles. (Besides, anything it could have matched is already caught in the last capture.) Next, define exactly what is allowed in a 'Person', and refine your two captures to just capture that.

What I suspect is happening is that some of your lines have whitespace at the end. This will then mean that the whole line ends up in $Person1, and $Person2 is empty. (Because the whitespace requirement is the only thing stopping the first capture from capturing the whole rest of the line.) I'm guessing putting (\w+) as your captures will likely do what you want, and solve your problem.


In reply to Re: need helpt to fix "use of uninitialized value..." by DStaal
in thread need help to fix "use of uninitialized value..." by mlebel

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.