Hello everyone,

I had a friend help me make the following code a while back and unfortunately this friend has passed away.

The original script where this code belongs inside works, but it is having unexpected behaviors. So after turning on warnings, I discovered that I am getting the following error 5 times when I run the script:

 "Use of uninitialized value within %PairsOf in concatenation (.) or string at ./test_removing_pair_unitialized_value_error.pl line 22, <DATA> line 14."

I don't know if it's the cause of the unexpected behavior in my script but I would certainly like to have this fixed.

Here is a part of my script at it's simplest form..:

#!/usr/bin/perl use strict; use warnings; my @PairLines; my %Pairs; my %PairsOf; @PairLines = <DATA>; chomp(@PairLines); foreach my $Line (@PairLines) { chomp $Line; $Line =~ s/^\s*//; $Line =~ s/\s*$//; if ($Line =~ m/^Pairing Start (.*)\s+(.*).*/) { my $Person1 = $1; my $Person2 = $2; $Pairs{$Person1} = $Person1 if (!defined($Pairs{$Person1})); $Pairs{$Person2} = $Person2 if (!defined($Pairs{$Person2})); $PairsOf{$Person1} = $PairsOf{$Person1} . " " . $Person2; $PairsOf{$Person2} = $PairsOf{$Person2} . " " . $Person1; } } __DATA__ Pairing Start Person1 Person2 Pairing End ########################################### Pairing Start Person1 Person3 Pairing End ########################################### Pairing Start Person1 Person4 Pairing End ########################################### Pairing Start Person1 Person5 Pairing End ########################################### Pairing Start Person2 Person3 Pairing End

Would anyone know a quick fix to this without re-writing the whole thing?

Thanks...


In reply to 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.