Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Testing on perl 5.6.1 and 5.8.0 $FORMAT_LINES_PER_PAGE defaults to 60, but $FORMAT_LINES_LEFT starts at 0. I would expect that it start a 60. When I specifically set $FORMAT_LINES_LEFT=60 once it hits zero it rolls around to 99999999 instead of resetting to 60. My code contains nested loops and each loop sets the format and calls write. All output is to STDOUT. What am I missing? Thanks.

Replies are listed 'Best First'.
Re: $FORMAT_LINES_LEFT question.
by duff (Parson) on Jan 30, 2004 at 21:35 UTC

    I guess no one really has an answer for this so I'll have a go ...

    I think that $FORMAT_LINES_LEFT is only relevant if you happen to specify the FILEHANDLE_TOP format for your handle. In your case, you need STDOUT_TOP. That's why it wraps to 999999 rather than 60. In any case this feels like a bug.

    And I don't think that $FORMAT_LINES_LEFT actually starts at zero. I think it starts life as undefined which, of course, numifies to 0. Perl probably checks for the undefinedness of this variable so that you can have the first page headerless and longer than all of the rest if you want to. Then from that point on it sets $FORMAT_LINES_LEFT = undef if $FORMAT_LINES_LEFT < 1; because I think the undefined value in $FORMAT_LINES_LEFT is what triggers the output of the header (FILEHANDLE_TOP) and causes perl to set $FORMAT_LINES_LEFT = $FORMAT_LINES_PER_PAGE -number of lines in header - 1 (The -1 is for the line just printed (the first line))

    Caveat lector of course as I'm just guessing. It's been many many many years since I've actually used formats. (I believe perl4 was the perl du jour when last I used them). I'm sure there's some simpler explanation, but since I can't think of it, this will give someone else target good target practice :-)

      $- and $= are magically bound to fields in the currently selected IO handle, and can only be integers. Watch:
      $ perl -we'$= = "123 abc"; print $=' Argument "123 abc" isn't numeric in scalar assignment at -e line 1. 123 $ perl -we'$= = undef; print $-' Use of uninitialized value in scalar assignment at -e line 1. 0
      Whatever you feed them is converted to an integer (with a warning, if appropriate) as it is stored. (In the case of $-, it also is made 0 if it was negative.)

      One of my all time favorite warning messages:

      $ perl -we'undef $=; print $-' Use of uninitialized value in undef operator at -e line 1. 0
Re: $FORMAT_LINES_LEFT question.
by b10m (Vicar) on Jan 30, 2004 at 19:40 UTC

    Please specify what you mean with these variables, for they aren't default Perl parameters, AFAIK.

    $ perl -e 'print "Per page = $FORMAT_LINES_PER_PAGE\n";' Per page =

    In other words: I have no clue what you're asking for (and I guess/hope I'm not the only one :) Please specify a little more of your problem.

    Update: I stand/sit corrected. I wasn't thinking ...

    --
    b10m

    All code is usually tested, but rarely trusted.
      He's using the English.pm names for $%, $=, and the like. Format variables.

      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      Type "perldoc perlvar" at your shell prompt and search for "FORMAT_LINES_LEFT". These are just the "use English" versions of the standard perl cryptic variables like $- and $=, etc.