Formats re-setting top of page format

T

Tony

Hi

This is a small version that shows the problem.
If it stays in the while loop it only prints
the top format the first time around then dosen't
print the top format for the next sixty odd iterations
which seems normal but not quite what I need.

If the program exits and is re-started it does the same
top only first time around.
Each iteration it creates a new tempfile.
Tried setting $- = 0; had no effect.

Seems I need to se-set the top format after
each iteration through the while loop.
Is this possible?

In the past I just used print instead of write
for the headings or exited and re-started the
program but would like to stay in it this time.

This is perl, v5.6.1 built for i386-linux

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

use Fcntl; # for temp file
use POSIX qw(tmpnam); # for temp file

while (1) {

print "Enter Name: ";
chomp( my $name = <STDIN> );

# -------------------------------------------------------------
my $tempfile;

do { $tempfile = tmpnam() }
until sysopen( FH, $tempfile, O_RDWR | O_CREAT | O_EXCL );

END { unlink($tempfile) or die "Couldn't unlink $tempfile : $!" }

# -------------------------------------------------------------
format FH_TOP =
Page @<<<
$%
Name
-----------+
..
format FH =
@<<<<<<<<<<
$name
..
write FH;
print FH "\n q to continue\n";
close FH;

# -------------------------------------------------------------

system("less $tempfile") && warn "Can't page tempfile";

print "\nquit (y|N): ";
chomp( my $quit = <STDIN> );
if ( $quit eq 'y' ) { exit; }
} # end while
exit;
 
J

Jay Tilton

: This is a small version that shows the problem.
: If it stays in the while loop it only prints
: the top format the first time around then dosen't
: print the top format for the next sixty odd iterations
: which seems normal but not quite what I need.
:
: If the program exits and is re-started it does the same
: top only first time around.
: Each iteration it creates a new tempfile.
: Tried setting $- = 0; had no effect.

select() the output filehandle before assigning $- = 0;
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top