Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I'm using perl format to print variable field data fields having new lines

#!/usr/bin/env perl use warnings; my $f = "format = \n" . ('^*' . '|') x 3 . "~~\n" . '@row' . "\n" . ".\n"; eval($f); my $f = "format = \n" . ('^*' . '|') x 3 . "~~\n" . '@row' . "\n" . ".\n"; eval($f); print $f, "\n"; my @row = ('line1 line3 ', 'line4 line5 line6 line7 ', 'line8' ); write; exit

but this gives me weird results, when I reduce num cols to 2 then it works as per documentation. Need your help in getting this code work.

exit

Replies are listed 'Best First'.
Re: perlform ^* variable field length
by pme (Monsignor) on Apr 27, 2015 at 15:38 UTC
    Hi AM,

    Could you provide your perl variables to print and the required output format? You should also read perlform to understand perlform's concept.

      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!

        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.

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