in reply to Re^2: Error: Use of uninitialized value $item in concatenation (.) or string at...
in thread Error: Use of uninitialized value $item in concatenation (.) or string at...
if ($line =~ /^Parsing \[(sent. \d+) len. \d+\]: \[(.+)\] +/) { #$one_match_ref->[1] = $1; ##Multiple in file #$one_match_ref->[2] = $2; #$one_match_ref->[2] =~ s/,//g; my $nocomma_sent = $2; $nocomma_sent =~ s/,//g; push( @{$one_match_ref}, $1, $nocomma_sent); }
This might be the source of one of your uninitialized values.
See perlre for details of the match variables ($1, $2, etc.). The important thing here is that these variables are reset by the next successful match. If your substitution to remove commas finds any, then it is a successful match, after which $1 and $2 are reset to undef. Thus, if $nocomma_sent has any commas in it, when you push $1 onto your array you will be pushing undef.
One way to avoid this is to push $1 before performing the substituion:
if ($line =~ /^Parsing \[(sent. \d+) len. \d+\]: \[(.+)\] +/) { push( @{$one_match_ref}, $1); my $nocomma_sent = $2; $nocomma_sent =~ s/,//g; push( @{$one_match_ref}, $nocomma_sent); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Error: Use of uninitialized value $item in concatenation (.) or string at...
by jonc (Beadle) on Jun 11, 2011 at 02:31 UTC | |
by ig (Vicar) on Jun 11, 2011 at 05:25 UTC | |
by AnomalousMonk (Archbishop) on Jun 11, 2011 at 16:09 UTC | |
by jonc (Beadle) on Jun 11, 2011 at 19:05 UTC | |
by AnomalousMonk (Archbishop) on Jun 12, 2011 at 06:43 UTC | |
by ig (Vicar) on Jun 13, 2011 at 10:26 UTC |