#!/usr/bin/env perl use strict; use warnings; #Your code to create a two-d array here my @two_d; #Three different ways to create the array: #1) Adding an anonymous array during each iteration for my $i (0..4) { push @two_d, [ ('x') x 10 ]; } #2) Pushing a reference to a new inner array onto the array #for my $i (0..4) { # my @inner = ('x') x 10; # push @two_d, \@inner; #} #3) Autovivifying the inner arrays: #for my $i (0..4) { # for my $j (0..9) { # $two_d[$i][$j] = 'x'; # } #} print "After initial creation:\n"; print_2d(); set_2d(5, 0, 'o'); set_2d(9, 3, 'o'); set_2d(2, 4, '*'); print "After setting three cels:\n"; print_2d(); #if you choose to implement the bonus, un-comment the following four lines: set_2d(11, 4, '-'); set_2d(2, 8, '-'); print "After (NOT) setting out-of-range cells:\n"; print_2d(); sub print_2d { for my $row (@two_d){ print "@$row\n"; } } sub set_2d { my ($x, $y, $char) = @_; if ($y >= @two_d){ warn "$y out of range for Y-coordinate\n"; } elsif ($x >= @{$two_d[$y]}) { warn "$x out of range for X-coordinate\n"; } else { $two_d[$y][$x] = $char; } }