in reply to Initialize a 2D array with zeros

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11157035 use warnings; my $n = 4; my $m = 7; my @array = map [ (0) x $m ], 1 .. $n; use Data::Dump 'dd'; dd @array;

Outputs:

( [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], )

Replies are listed 'Best First'.
Re^2: Initialize a 2D array with zeros
by eyepopslikeamosquito (Archbishop) on Jan 17, 2024 at 05:30 UTC