in reply to Separating array contents
This creates an array of arrays split at "!", potentially with empty entries at beginning or end. Similar to choroba's complex solution in Re^2: Separating array contents
use strict; use warnings; use Data::Dumper; my @arr = qw/ ! my name ! is ! Achint ! I need ! help ! /; my @out = ( [] ); for( @arr ) { if( /^!$/ ) { push @out, []; } else { push @{ $out[-1] }, $_; } } print Dumper \@out;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Separating array contents
by space_monk (Chaplain) on Jun 07, 2013 at 12:29 UTC |