With formline the double tilda ~~ is applied to the entire format "picture" so it doesn't do what you want it to do.
Instead you have to repeat the formline() while there is still data to write. I've modified the example to show one way of doing it:
#!/usr/bin/perl -w use strict; # Store the formats in variables (you don't have to use here-docs) my $header = << 'HEADER'; Menge Art.nr. Bezeichnung Preis($) Gesamt +($) __________________________________________________________________ +___ HEADER my $body = << 'INHALT'; @<<<< ^<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>> @>>>>>>>>> INHALT my $continue = << 'INHALT2'; ^<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<< INHALT2 my $footer = << 'FOOTER'; __________________________________________________________________ +___ Warenwert: @>>>>>>>>> FOOTER # Sample data my @bestellung = ('Long ID number|123456789012345|3.99|7', 'Text two, this is a long line|2|5.49|8', 'Text three, this is the longest line|3|7.89|9') +; formline($header); foreach (@bestellung) { my ($text, $nr, $preis, $menge) = split /\|/; my $summe = sprintf("%.2f", $menge*$preis); formline($body, $menge,$nr,$text,$preis,$summe); while (length $nr or length $text) { formline($continue, $nr,$text); } } formline($footer, 1234); print $^A; # Print the accumulator $^A = ''; # Clear the accumulator __END__ Prints: Menge Art.nr. Bezeichnung Preis($) Gesamt +($) __________________________________________________________________ +___ 7 123456789 Long ID number 3.99 27.93 012345 8 2 Text two, this is a long 5.49 43.92 line 9 3 Text three, this is the 7.89 71.01 longest line __________________________________________________________________ +___ Warenwert: 1234
--
John.
In reply to Re: How to route a format into a variable
by jmcnamara
in thread How to route a format into a variable
by ppm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |