Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- creating an array of $n elements
November 5, 2008, 3:31 am
rate this thread
a list in Perl with all elements initialized to the same value, is
there a one-liner? The best I can come up with is "$a[$n] = 0; pop
@a;" which will give me an array of $n undefs, but it seems a bit
inefficient. Any ideas? Thanks.
Re: creating an array of $n elements
$ perl -le'
my $n = 7;
my @a = ( undef ) x $n;
print Dumper \@a;
$VAR1 = [
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
- Petr Vileta (fidokomik)
November 5, 2008, 8:16 am
- » FAQ 4.43 How do I compute the difference of two arrays? How do I compute the intersection...
- — Previous thread in » PERL Discussions