John Sampson wrote:
Hello -

I am trying to accumulate items in a flat list (array) by
concatenating on to it
the scalars contained in arrays which in turn are contained in arrays. The data
is to be read in from a file rather than existing as literals in my code.

Everything I try either crashes the computer or gives me an array of
arrays instead
of a flat list.

I have been programming in Unicon which has a concatenate operator, but Perl
makes very heavy weather of nested list management. Should I switch to Lisp,
or is there a way of doing what I want to do in Perl?

I'm intrigued to know what makes you think Perl is poor at list
management.

  push @a, @b;

will concatenate the data in @b onto the end of @a if that's what you
want.

But it sounds very much like you've decided to read data from a file
into an array of arrays and then take it out again. It's likely to be
better just to read the data in and store it in its final form straight
away.

It would help if you'd given some sample data, but the program below
accumulates all the lists in @aofa into array @flat.

HTH,

Rob



use strict;
use warnings;

my @aofa = (
  [1,2,3,4],
  [5,6,7,8],
  [9,10,11,12],
);

my @flat;

push @flat, @$_ foreach @aofa;

print "@flat\n";

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to