in reply to Re^4: perlform ^* variable field length
in thread perlform ^* variable field length

It seems to be that this is your input:
my @row = ( 'col1:line1 col1:line2', 'col2:line1', 'col3:line1', 'col4:line1', 'col5:line1 col5:line2', 'col6:line1 col6:line2 col6:line3 col6:line4' );
and this is the required output:
col1:line1|col2:line1|col3:line1|col4:line1|col5:line1|col6:line1 col2:line2| | | |col5:line2|col6:line2 | | | | |col6:line3 | | | | |col6:line4
Is that correct?

Please read you comment carefully before posting.

Replies are listed 'Best First'.
Re^6: perlform ^* variable field length
by Anonymous Monk on Apr 28, 2015 at 08:47 UTC

    yes, its correct. just one correction in the desired output which you have posted in row 2

    col1:line1|col2:line1|col3:line1|col4:line1|col5:line1|col6:line1 ->col1:line2| | | |col5:line2|col6:line2 | | | | |col6:line3 | | | | |col6:line4
      This piece of code does what you need except that the field width is fixed.
      use warnings; use strict; my @row = ( 'col1:line1 col1:line2', 'col2:line1', 'col3:line1', 'col4:line1', 'col5:line1 col5:line2', 'col6:line1 col6:line2 col6:line3 col6:line4' ); format STDOUT = ^>>>>>>>>|^>>>>>>>>|^>>>>>>>>|^>>>>>>>>|^>>>>>>>>|^>>>>>>>>|~~ @row . write;
      However using variable field width gives "Out of memory", I do not know why.
      format STDOUT = ^*|^*|^*|^*|^*|^*|~~ @row .

        I need to use variable field width and I know that using variable field ^* alongwith ~~ gives Out of Memory, that's why I'm here to seek solution. Isn't there other logic other than the perlform that can be implemented ?

        Hi, I managed to do the get the desired result by below code :

        my @row = ('col1 : line1 col1 : line2', 'col2 : line1', 'col3 : line1', 'col4 : line1', 'col5:line1 col5:line2', 'coll6 : line1 coll6 : line2 coll6 : line3 coll6 : line4' ); while ( join('',@row) ) { for(my $i=0;$i<=$#row;$i++) { my @a = split (/\n/,$row[$i]); my $s = shift(@a); print ($s? $s . '|' : '|'); $row[$i] = join("\n",@a); } print "\n"; }

        it gives desired output as :

        col1 : line1|col2 : line1|col3 : line1|col4 : line1|col5:line1|coll6 : + line1| col1 : line2||||col5:line2|coll6 : line2| |||||coll6 : line3| |||||coll6 : line4|

        but condition in while loop looks kinda ugly, can be below code be further reduced ?