in reply to format function


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.

Replies are listed 'Best First'.
Re: Re: format function
by Albannach (Monsignor) on Oct 02, 2003 at 04:17 UTC
    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.

        Thanks for the suggestions. This is a strange situation. The system I am working with is an older Solaris 7 server. For some reason, it only has the perl executable, not the full distro. This may be part of the problem.