I have a problem with initialized values. I have a script which has method:
sub compare_with_terminal {
use Term::Size::Any qw( chars pixels );
my $columns = 0;
my $rows = 0;
($columns, $rows) = chars *STDOUT{IO};
print "Columns: ".$columns."\n"; #line 73
print "Rows: ". $rows."\n";
if($height > $columns || $width > $rows){
print "Bigger than terminal: ";
my $option = <>;
chomp($option);
if($option eq "N"){
print "End.";
exit 0;
}
}
}
I created and initialized two values $columns and $rows. But, when I run this script, I get:
Use of uninitialized value $columns in concatenation (.) or string at ./perl/script.pl line 73 (#1) (W uninitialized) An undefined value was used as if it were already defined. It was interpreted as a "" or a 0, but maybe it was a mistake. To suppress this warning assign a defined value to your variables.
$rows has same error.
These errors say that I didn't initialize variable $columns, but I did. Anyone can explain me and try to solve this problem?
$columnsin a string anywhere in your snippet) - ThisSuitIsBlackNot$columnsand$rowsvariables. They are numbers I hope, not a strings. On windows everything works fine and I don't get any errors. - Developus$columnshas an undefined value, not that it wasn't "initialized". (In fact, it's impossible not to initialize in Perl. Scalars are automatically initialized toundef, and arrays and hashes are initialized empty.) - ikegami