in reply to Re^2: Splitting multiline scalars into different array entries
in thread Splitting multiline scalars into different array entries
I'm certain that this isn't the best way, but it works:
giving an output offoreach my $row (@AoA) { my @foo = break_up( $row ); if( $foo[0] =~ /ARRAY/ ) { push @new_rows, @foo; } else { push @new_rows, [ @foo ]; } } print Dumper(\@new_rows); sub break_up { my $row = shift; my $uses_newlines = 0; $uses_newlines++ if join( "", @$row ) =~ /\n/m; return @$row unless $uses_newlines; my @tmp; map { push @tmp, [ split /\n/ ] } @$row; my @row; for( my $i = 0; $i <= $#tmp; $i++ ) { for( my $j = 0; $j <= $#tmp; $j++ ) { $row[$i][$j] = shift @{$tmp[$j]}; } } return @row; }
$VAR1 = [ [ 'single', 'cell', 'values' ], [ 'are', 'really', 'easy' ], [ 'but', 'these', 'aren\'t' ], [ 'multiline', 'cells', 'suck' ], [ 'stilton', 'is', 'great' ], [ 'back', 'to', 'life' ], [ 'back', 'to', 'reality', 'with', 'more', 'cells' ] ];
Interesting problem :) What's this for, if I can ask?
-- Foxcub
#include www.liquidfusion.org.uk
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Splitting multiline scalars into different array entries
by davis (Vicar) on Aug 05, 2005 at 11:34 UTC |
In Section
Seekers of Perl Wisdom