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

Hi, here's what I'm trying to do :

my @row = ('col1 : line1 col2 : line2', 'col2', 'col3 f1 col3 f2', 'col4', 'col5:line1 col5:line2', 'coll6 : line1,line1 coll6 : line2,line2 coll6 : line3,line3 coll6 : line4,line4' ); my $f = "format = \n" . ('^*' . '|') x scalar(@row) . "~~\n" . '@row' . "\n" . ".\n"; eval($f); write;

want desired result as :

col1:line1|col2|col3 f1 col3 f2|col4|col5:line1|col6: line1,line1 col2:line2||||col5:line2|col6:line2,line2 |||||col6:line3,line3 |||||col6:line4,line4

but running the code gives: Out of memory!

Replies are listed 'Best First'.
Re^3: perlform ^* variable field length
by pme (Monsignor) on Apr 27, 2015 at 19:42 UTC
    I am afraid you still have not read the man. It is necessary to understand how perlform works.

    Your problem description is still rather dim. eg. what does 'col2' and 'f1' mean? Do you have 4 input lines having 6 columns each? We are unable to help you without clear problem description.

      Hi, I'm having an array that has 6 cols/fields and a col/field can have either a single line or multiple lines. So, I can say a array looks like as :

      ('col1 : line1 col2 : line2', 'col2 : line1', 'col3 : line1', 'col4 : line1', 'col5:line1 col5:line2', 'coll6 : line1 coll6 : line2 coll6 : line3 coll6 : line4' );

      and I want to print the content of array as :

      col1:line1|col2:line1|col3:line1|col4:line1|col5:line1|col6: line1 col2:line2||||col5:line2|col6:line2 |||||col6:line3 |||||col6:line4

        This seems to be exactly what you posted in Re^2: perlform ^* variable field length. You were asked to clarify, not repeat yourself.

        What I don't understand, for example, is why the second line in your "desired result" should be:

        col2:line2||||col5:line2|col6:line2

        rather than:

        |col2:line2|||col5:line2|col6:line2
        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.