Perl: the Markov chain saw PerlMonks

### Re^3: Splitting multiline scalars into different array entries

by broquaint (Abbot)
 on Aug 05, 2005 at 11:23 UTC ( #481198=note: print w/replies, xml ) Need Help??

Ah yes, it seems I missed the transposition.
```use Algorithm::Loops 'MapCar';

my @results = map {
grep(/\n/,@\$_)
? MapCar {[@_]} map([split "\n"], @\$_)
: \$_
} @AoA;
And to be sure:
```use Test::More tests => 1;

my @AoA = (
[qw/single cell values/],
[qw/are really easy/],
[ "but\nmultiline\nstilton",
"these\ncells\nis",
"aren't\nsuck\ngreat" ],
[qw/back to life/],
[qw/back to reality with more cells/]
);

my \$desired = [
[ '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' ]
];

use Algorithm::Loops 'MapCar';
my @results = map {
grep(/\n/,@\$_)
? MapCar {[@_]} map([split "\n"], @\$_)
: \$_
} @AoA;

is_deeply \@results, \$desired, "The arrays match!";
HTH

_________
broquaint

Replies are listed 'Best First'.
Re^4: Splitting multiline scalars into different array entries
by davis (Vicar) on Aug 05, 2005 at 11:29 UTC
broquaint: Thank you very much. I had just seen frodo's link, and was struggling with MapCar myself. That's exactly what I was after.

davis
Kids, you tried your hardest, and you failed miserably. The lesson is: Never try.
Re^4: Splitting multiline scalars into different array entries
by Anonymous Monk on May 15, 2012 at 05:40 UTC
i wanna split a file which has 3 char and all 21 values in a single line ie each char has 7 values.so i need to split it as 7 in each line by input file.

Create A New User
Node Status?
node history
Node Type: note [id://481198]
help
Chatterbox?
 [Corion]: Actually bsd_glob '{www.,}perlmonks .{com,net,org}', plus css.perlmonks.org I think [Corion]: Sad that Let's Encrypt does not allow wildcard certificates, but they could be somewhat of a hassle to verify [Discipulus]: since 2002 I just usewd www.perlmonks.org and good morning Discipulus .oO(maybe a PM discussion?)

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2017-09-26 07:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
During the recent solar eclipse, I:

Results (292 votes). Check out past polls.

Notices?