in reply to Use of uninitialized value $data

My hint is to not trust your logging further up and to move the logging to where the problem is. If $data is undef, then $datapair does not contain a =.

So, investigate $datapair and the contents of @data just before your loop.

Maybe/most likely, $line is not what you think it is. Maybe it ends with a comma and a newline, and split helpfully keeps that newline as its own element in @data?

Replies are listed 'Best First'.
Re^2: Use of uninitialized value $data
by ImJustAFriend (Scribe) on Nov 13, 2018 at 21:57 UTC
    Thanks for the input! I just ran it again. Here is what $line (one example) looks like in my debug log (obscured for privacy):
    "line: label1=N,label2=N,label3=N,label4=NNNNNNNNNNN,label5=N,label6=W +WWN"
    So it looks as though $line is populating properly... hmmmm....

      Then please show us the relevant code+data that produces the output.

      I can't reproduce the problem using the following, very short program:

      #!perl use strict; use warnings; my $line = "line: label1=N,label2=N,label3=N,label4=NNNNNNNNNNN,label5 +=N,label6=WWWN"; my @data = split(',', $line); foreach my $datapair (@data) { my ($label, $data) = split('=', $datapair); print "label: $label; data: $data\n"; #print OUT1 "$data;"; } __END__ label: line: label1; data: N label: label2; data: N label: label3; data: N label: label4; data: NNNNNNNNNNN label: label5; data: N label: label6; data: WWWN

      ... to me, that means, you are either doing something differently in your code that you haven't shown, or your data is something else.

      Perhaps use a hash?
      #!/usr/bin/perl use strict; use warnings; my $line ="line: label1=N,label2=N,label3=N,label4=NNNNNNNNNNN,label5= +N,label6=WWWN"; my %values = $line =~ /(\w+)=(\w+)/g; foreach my $label (sort keys %values) { print "$label $values{$label}\n"; } __END__ label1 N label2 N label3 N label4 NNNNNNNNNNN label5 N label6 WWWN