Format - stopping at certain page

B

Brad Walton

I would like the output of data to stop at a certain page number. This is
the test script I have been working on:

----
#!/usr/bin/perl
use strict;
use warnings;

my ($key, $value);
$= = 10; # Number of lines before new page

open (FILE, 'greatergreen.plr') or die "Cannot open: $!";
while (<FILE>) {
chomp;
if ($_ =~ /(.*)\=\"(.*)\".*/) {
$key = $1;
$value = $2;
write if $% < 2;
}
}
close (FILE);

format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
$key, $value
..

format STDOUT_TOP =

Page @<<
$%

Variable Setting
========================= =================
..
----

And this is the output:

----
Page 1

Variable Setting
========================= =================
Track File LOCATION
Track Description LongBeach
AI Database File LOCATION
Profile Vehicle File TEAMS\GT
Vehicle File TEAMS\GT
?
Page 2

Variable Setting
========================= =================
Sim Vehicle File TEAMS\GT
----

I would like it to stop at the end of Page 1, but it's leaking on to page 2.
I assume this is happening because the page counter isn't updated until
after it's called for write.

Thanks for any help,
Brad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top