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


In reply to Uninitialized warnings trouble by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.