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

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 .

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

    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 ?

Re^8: perlform ^* variable field length
by Anonymous Monk on Apr 28, 2015 at 10:41 UTC

    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 ?