Dear Monks,
I'm dealing with some csv-files that I use as a basis to make various calculations. It all works fine and the calculations are correct except that while using:
#!/usr/bin/perl -w # use warnings
use strict;
use diagnostics;
I remain having the problem that I frequently get the message:
Use of uninitialized value in numeric eq (==) at
The reason for these warnings are probably 'missing values' in the csv-file. $_ will be
undefined as I understood from documentation. While using things like (as mentioned in an earlier post):
use Data::Table;
$joinTable->colsMap( sub { $_->[4] = skipblanks( $_->[4] ) } );
sub skipblanks {
my @data = @_;
my $x = 0;
foreach $x (@data) {
if ($x) {
$x =~ s/,/\./g;
}
return $x;
}
}
or
use Data::Table;
$joinTable->colsMap( sub { $_->[4] = to_int_or_zero( $_->[4] ) } );
sub to_int_or_zero {
my $value = shift;
if (
defined($value)
&& ( $value =~ m/^\d+$/
|| $value =~ m/^-?\d+\.?d*$/ )
)
{
return $value;
}
else {
return 0;
}
}
The message is still appearing sometimes. What am I doing wrong? Maybe not ideal in every situation but what would work for me is to fill all blanks with '0' (zeroes). Is there a way to do this for the whole csv-file at the beginning of the script. Or maybe some other straightforward or generic way to make $_ always
initialized in order to avoid the warnings?
Thanks,
Gert
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.