Hello monks, I am in need of assistance please. I have a file I am parsing. At the end of parsing, I am left with lines that look like this:
label1=data1,label2=data2, ...
There can be a variable number of label/data pairs on each line. My code for parsing these lines:
my @data = split(',', $line);
foreach my $datapair (@data) {
my ($label, $data) = split('=', $datapair);
print "label: $label; data: $data\n";
print OUT1 "$data;";
}
When I run the code, I get on my stderr
Use of uninitialized value $data in concatenation (.) or string at ./t
+est.pl line 124, <IN4> chunk 2147.
Use of uninitialized value $data in concatenation (.) or string at ./t
+est.pl line 125, <IN4> chunk 2147.
I can see in my debug logs (further up, code not shown) that I am getting @data loaded appropriately with lines like my sample lines above. So why is $data uninitialized? This has been driving me nuts for a couple of hours now. Thanks all!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.