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

I'm using the format function. I'm having problems changing the page length with $= It keeps reverting to 60 lines. My filehandle is STDOUT. I need to use format becuase this is an old version of perl. Thanks.
$= = 600; format STDOUT_TOP = + queue proc_status + | | +proc prio | msg | log broadcast Share +d Mem +name | type | node Segm +ents . format STDOUT = @||||||| @|| @|||| @||| @|| @|||||||||| @|||||||| @ @ @ + @ @ @ @ @ @ @ @ @ @ @ $x[0],$x[1],$x[2],$x[3],$x[4],$x[5],$x[6],$x[7],$x[8],$x[9],$x[10],$x[ +11],$x[12] ,$x[13] .

Replies are listed 'Best First'.
Re: format function
by jmcnamara (Monsignor) on Oct 01, 2003 at 21:44 UTC

    The bare @'s in the format aren't syntactically correct. They should be @|, @< or @> even though you only want one character.

    The following works. Change $= and the "Mem Segments" part of the format to suit.

    #!/usr/bin/perl -w $= = 10; my @x = (1..10); format STDOUT_TOP = + queue proc_status + | | +proc prio | msg | log broadcast Share +d Mem +name | type | node Segm +ents . format STDOUT = @||||||| @|| @|||| @||| @|| @|||||||||| @|||||||| @< @< + @< @x . for (1..12) { write; @x = map {$_ +1} @x; } __END__ Prints: + queue proc_status + | | +proc prio | msg | log broadcast Share +d Mem +name | type | node Segm +ents 1 2 3 4 5 6 7 8 9 + 10 2 3 4 5 6 7 8 9 10 + 11 3 4 5 6 7 8 9 10 11 + 12 4 5 6 7 8 9 10 11 12 + 13 5 6 7 8 9 10 11 12 13 + 14 6 7 8 9 10 11 12 13 14 + 15 ^L + queue proc_status + | | +proc prio | msg | log broadcast Share +d Mem +name | type | node Segm +ents 7 8 9 10 11 12 13 14 15 + 16 8 9 10 11 12 13 14 15 16 + 17 9 10 11 12 13 14 15 16 17 + 18 10 11 12 13 14 15 16 17 18 + 19 11 12 13 14 15 16 17 18 19 + 20 12 13 14 15 16 17 18 19 20 + 21

    --
    John.

      The bare @'s in the format aren't syntactically correct.
      Can you elaborate on that? They seem to work just fine, and how else would one get a single-character field anyway? The relevant doc is not specific on this, but I see that the Notes section has an example of a lone @ as a field. Your example works fine with the extra < removed, giving the expected output of the single most significant digit.

      For that matter mhearse's example worked just fine for me also, once I removed the excess @ fields, so I suspect something else is going on in his case.

      --
      I'd like to be able to assign to an luser


        You are correct. They are valid.

        When I ran mhearse's example code I got the following error:

        Array found where operator expected at format.pl line 17, at end of +line (Missing operator before ?) syntax error at format.pl line 17, near "@ @ @ @ "
        I misinterpreted this to mean that the bare @'s were the problem. However, as you point out, they are in fact valid and the error comes from the line wrapping around.

        In which case, I can't say what is the problem. Setting $= to 600 or any other value works fine for me with perls from 5.00405 onwards.

        --
        John.