In this case, you (now) know that missing or undefined values (for the format string) are the cause of the warnings. Then, why not mute them for the relevant code for there is nothing else to "[miss] out on"?
... { no warnings 'uninitialized'; printf $format , @values; } ...
Since missing values do not matter, both Not_a_Number's and Grandfather's suggestion will work equally.
In case one would need to show the values under proper column headings, then you would need to fill in the missing or undefined values with substitute values (empty string, 0, -, N/A, /, etc). That may also call for the data to be properly formatted such that missing values are represented by their absence.
use strict; use warnings; my $title = " A B C D\n"; my $format = "%2d %2d %2d %2d\n"; print $title; printf $format , @{ $_ } for fetch_data(); sub fetch_data { my @data; while ( my $line = <DATA> ) { next if $line =~ m/^\s*#/ or $line =~ m/^\s*$/ ; push @data , [ map get_standin( $_ ), split /;/ , $line , 4 ]; } return @data; } sub get_standin { my ( $in ) = @_; my $standin = 0; return $standin unless defined $in; for ( $in ) { s/^\s+//; s/\s+$//; } return length $in ? $in : $standin; } __DATA__ # Data (say 2 digit numbers at most, or missing). 1; 2 ; 3; 5 9;97; ;0 ; 6 ; 8 ; ;;; 76
In reply to Re^3: How to avoid "Use of uninitialized value" with printf?
by Anonymous Monk
in thread How to avoid "Use of uninitialized value" with printf?
by bobdabuilda
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |