Formats re-setting top of page format

Discussion in 'Perl Misc' started by Tony, Sep 4, 2003.

  1. Tony

    Tony Guest

    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;
    Tony, Sep 4, 2003
    #1
    1. Advertising

  2. Tony

    Jay Tilton Guest

    Tony <> wrote:

    : 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;
    Jay Tilton, Sep 4, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Frederic HOUDE
    Replies:
    4
    Views:
    586
    Frederic HOUDE
    Aug 31, 2004
  2. Replies:
    0
    Views:
    389
  3. Cuthbert
    Replies:
    8
    Views:
    422
    Ancient_Hacker
    Sep 13, 2006
  4. AAaron123
    Replies:
    6
    Views:
    560
    AAaron123
    Nov 5, 2009
Loading...

Share This Page