in reply to How to pass a Format Heading from a variable?

Having never used Perl's format facility before I decided to have a little play. It turns out you can call functions to generate picture data so it's easy to generate a header for each page:

use strict; use warnings; my ($title, $name, $format, $matches, $runs); format DATA2_TOP= @||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| title() ============================================================ Name Format of match matches played runs scored ============================================================ . format DATA= @<<<<<<<<<<<<<<<< @<<<<<<<<< @######### @######## $name, $format, $matches, $runs . my @array = <DATA>; $^L = "--------- page break\n"; $^ = 'DATA2_TOP'; $~ = 'DATA'; $= = 10; # 10 line pages to see page numbering working foreach (@array) { chop; ($name, $format, $matches, $runs) = (split(/!/)); write ; } sub title { return "Records/Data of the trio (Page $%)"; } __DATA__ sachin tendulkar!ODI!434!12000 sachin tendulkar!Test!246!10900 sachin tendulkar!T20!189!5000 sourav ganguly!ODI!334!8000 sourav ganguly!Test!235!5000 sourav ganguly!T20!124!1800 rahul dravid!ODI!387!9000 rahul dravid!Test!212!5980 rahul dravid!T20!43!1345

Prints:

Records/Data of the trio (Page 1) ============================================================ Name Format of match matches played runs scored ============================================================ sachin tendulkar ODI 434 12000 sachin tendulkar Test 246 10900 sachin tendulkar T20 189 5000 sourav ganguly ODI 334 8000 sourav ganguly Test 235 5000 sourav ganguly T20 124 1800 --------- page break Records/Data of the trio (Page 2) ============================================================ Name Format of match matches played runs scored ============================================================ rahul dravid ODI 387 9000 rahul dravid Test 212 5980 rahul dravid T20 43 1345

Note that I've changed the page length to 10 to get two pages generated. I've also changed the page format form feed string from Perl's default form feed character to make if clear where the page breaks are.

Premature optimization is the root of all job security