I have a program in Perl that reads one line at a time from an input data file and computes certain statistics. Then, it writes the result in a separate output file and reads a new line from the input data file, and so on...
Every now and then, while the program reads through my input data file, I get a warning about an "uninitialized value" and I would like to know which line in the input data file generates this warning. Is there any way I can tell Perl to print (to screen or file) the data point that is generating the error?
My actual code is pretty long so I'm posting just a portion of it to give an idea (together with the error message that I get when running the program.)
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Data::Dumper;
open (F, "input.csv");
my @lines=<F>;
close(F);
open (F1,'>>output.csv');
define my variables;
for (my $i=1; $i<@lines; $i++){
read in one line of data;
do stuff;
write to file;
}
close(F1);
The type of error I get when running the program is:
"Use of uninitialized value $Top5 in division (/) at builder.pl line 403 (#1)
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.