in reply to spliting arrays

This is my take on your problem using split twice with array of anonymous arrays.

#!/usr/bin/perl use strict; use warnings; my @strings; while (<DATA>) { # Split up input stream using dashes my @smallarray = split '-'; # @smallarray now has 'aaa bb +b ccc', etc. # Iterate through @smallarray items and split them up using s +paces # Create an array of anonymous array references # The references are the array resulting from split, using [] push(@strings, [split /\s/]) foreach (@smallarray); }
# The array of anonymous arrays now looks like this: # # $VAR1 = [ # 'aaa', # 'bbb', # 'ccc' # ]; # $VAR2 = [ # 'ddd', # 'eee', # 'fff' # ]; # $VAR3 = [ # 'ggg', # 'hhh', # 'iii' # ]; # $VAR4 = [ # 'jjj', # 'kkk', # 'lll' # ];
# Print out the whole AoA contents foreach my $arrayref (@strings) { print "$_\n" foreach @$arrayref; } print "----\n\n"; # Or just the contents of one group foreach my $item (@{$strings[0]}) { print "$item\n"; } __DATA__ aaa bbb ccc-ddd eee fff-ggg hhh iii-jjj kkk lll- __OUTPUT__ aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll ---- aaa bbb ccc

--
Allolex

Perl and Linguistics
http://world.std.com/~swmcd/steven/perl/linguistics.html
http://www.linuxjournal.com/article.php?sid=3394
http://www.wall.org/~larry/keynote/keynote.html