in reply to How to route a format into a variable


Here is a short example using formline and the accumulator based on your code. I simplified the INHALT format because I wasn't fully sure what you wanted to do with the ~~:
#!/usr/bin/perl -w use strict; # Store the formats in variables my $header = << 'HEADER'; Menge Art.nr. Bezeichnung Preis(?) Gesamt(?) __________________________________________________________________ +___ HEADER my $body = << 'INHALT'; @<<<< ^<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>> @>>>>>>>>> INHALT my $footer = << 'FOOTER'; __________________________________________________________________ +___ Warenwert: @>>>>>>>>> FOOTER # Sample data my @bestellung = ('Text one|1|3.99|7', 'Text two|2|5.49|8', 'Text three|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); } formline($footer, 1234); print $^A; # Print the accumulator $^A = ''; # Clear the accumulator __END__ prints: Menge Art.nr. Bezeichnung Preis(?) Gesamt(?) __________________________________________________________________ +___ 7 1 Text one 3.99 27.93 8 2 Text two 5.49 43.92 9 3 Text three 7.89 71.01 __________________________________________________________________ +___ Warenwert: 1234

See also Re: Formats and Variable Scope and Re: format and IO::String.

--
John.

Replies are listed 'Best First'.
Re: Re: How to route a format into a variable
by ppm (Novice) on Feb 12, 2003 at 18:52 UTC
    Hey John,

    thx a lot .. this was exactly what i tried to do .. know i've understand the usage of accumulator ;o) best regardes ppm

Re: Re: How to route a format into a variable
by ppm (Novice) on Feb 13, 2003 at 20:55 UTC
    Hello again,

    the formline works now fine .. but i've a new problem.

    >> I wasn't fully sure what you wanted to do with the ~~:

    I will format the Information at "Art.nr." and "Bezeichnung" for multiline output ... In the normal format i will do this with ~~ :

    format INHALT = @<<<< ^<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>> @>>>>>>>>> $menge,$nr,$text,$preis,$summe, ~~ ^<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<< $nr, $text .
    But this doesn't work with the formline example .. there are any solutions?

    thx again! ppm