Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Splitting multiline scalars into different array entries

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


in reply to Splitting multiline scalars into different array entries

use Data::Dumper; ## your @AoA here ... my @results = map { grep(/\n/, @$_) ? map([split "\n"], @$_) : $_ } @AoA; print Dumper( \@results );
If you want to update the original data just change the my @results = to @AoA =. Also you could use Scalar::Util::first there instead of grep if you're looking for an optimal solution.
HTH

_________
broquaint


Comment on Re: Splitting multiline scalars into different array entries
Download Code
Re^2: Splitting multiline scalars into different array entries
by davis (Vicar) on Aug 05, 2005 at 11:15 UTC
    Hmmm... that was my first result. See my desired output. Thanks anyway!

    davis
    Kids, you tried your hardest, and you failed miserably. The lesson is: Never try.
      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:
      HTH

      _________
      broquaint

        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.
        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://481189]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2015-07-02 01:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (25 votes), past polls