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

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

Replies are listed 'Best First'.
Re^7: perlform ^* variable field length
by pme (Monsignor) on Apr 28, 2015 at 09:32 UTC
    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 ?