Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,19 @@
sub make_array($ $){
# get array sizes from provided params, but force numeric value
my $x = ($_[0] =~ /^\d+$/) ? shift : 0;
my $y = ($_[0] =~ /^\d+$/) ? shift : 0;
# define array, then add multi-dimensional elements
my @array;
$array[0][0] = 'X '; # first by first element
$array[5][7] = 'X ' if (5 <= $y and 7 <= $x); # sixth by eighth element, if the max size is big enough
$array[12][15] = 'X ' if (12 <= $y and 15 <= $x); # thirteenth by sixteenth element, if the max size is big enough
# loop through the elements expected to exist base on input, and display the elements contents in a grid
foreach my $dy (0 .. $y){
foreach my $dx (0 .. $x){
(defined $array[$dy][$dx]) ? (print $array[$dy][$dx]) : (print '. ');
}
print "\n";
}
}

View file

@ -0,0 +1,19 @@
sub array {
my ($x, $y) = @_;
map {[ (0) x $x ]} 1 .. $y
}
my @square = array 3, 3;
# everything above this line is mostly redundant in perl,
# since perl would have created the array automatically when used.
# however, the above function initializes the array elements to 0,
# while perl would have used undef
#
# $cube[3][4][5] = 60 # this is valid even if @cube was previously undefined
$square[1][1] = 1;
print "@$_\n" for @square;
> 0 0 0
> 0 1 0
> 0 0 0