http://qs321.pair.com?node_id=11148831

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am trying to solve day 8, part a. of Advent of Code: https://adventofcode.com/2022/day/8 . I am being flooded with uninitialized value warnings for lines 52, 55, 72, and 75. Here is one:

Use of uninitialized value in numeric lt (<) at ./day8a-l.pl line 55, <$line> line 98

My input is 99 lines with 99 numbers ranging from 0-9 on each line(no whitespace). Here is my code:

#!/usr/bin/perl use strict; use warnings; my @row; my $current = 0; my $visible = 198; my $found = 0; open(my $lines, '<', 'input8.txt'); foreach (<$lines>) { chomp; for my $l (0..length()-1) { my ($digit) = /^.{$l}(.)/; if (defined $digit) { $row[$current][$l] = $1; } } $current += 1; } close $lines; open(my $line, '<', 'input8.txt'); $current = 0; while (<$line>) { chomp; if ($current > 0 and $current < 98) { $visible += 2; for (my $i = 1; $i < 98; $i++) { my $counter = 1; $found = 0; while ($row[$current][$i-$counter] < $row[$current][$i] an +d $found == 0) { $counter += 1; if ($counter == $i) { $visible += 1; $found = 1; $counter = 1; } } while ($row[$current][$i+$counter] < $row[$current][$i] an +d $found == 0) { $counter += 1; if ($counter == $i) { $visible += 1; $found = 1; $counter = 1; } } while ($row[$current-$counter][$i] < $row[$current][$i] an +d $found == 0) { $counter += 1; if ($counter == $current) { $visible += 1; $found = 1; $counter = 1; } } while ($row[$current+$counter][$i] < $row[$current][$i] an +d $found == 0) { $counter += 1; if ($counter == $current) { $visible += 1; $found = 1; $counter = 1; } } } } $current += 1; } close $line; print $visible . "\n";

I'd be really grateful for any suggestions. Thanks,

L