in reply to Fun with two-dimensional arrays
I don't know why you say the number of rows is hard coded. Why can't you just do this:
foreach my $row (0 .. $lastRow) { }
But you might consider not storing it as a 2-dimensional array, but rather as a 22x80 character-long string. Then traversal becomes simply a matter of using substr and multiplying indexes (and it duplicates the behavior of wrapping that most terminals exhibit):
my $screen = ' ' x ($rows * $columns); foreach my $row (0 .. $rows-1) { my $rowText = substr($screen, $row*$columns, $columns); } # sets text, returns old text. sub setTextAt { my $x = shift; my $y = shift; my $text = join('', @_); substr($screen, $y * $columns + $x, length($text), $text); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re(2): Fun with two-dimensional arrays
by FoxtrotUniform (Prior) on Aug 09, 2001 at 21:14 UTC | |
by George_Sherston (Vicar) on Aug 10, 2001 at 04:59 UTC | |
by bikeNomad (Priest) on Aug 09, 2001 at 21:23 UTC |
In Section
Seekers of Perl Wisdom