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

Hi, I want to use formline to format the output, but getting Undefined format "STDOUT" .

#!/usr/bin/env perl formline( "@<< @<< @<<", '1', '2', '2' ); write;

Error : Undefined format "STDOUT" called. Need help, whats wrong ?

Replies are listed 'Best First'.
Re: formline, undefined format STDOUT
by choroba (Cardinal) on Apr 20, 2015 at 13:19 UTC
    formline is low level function. As shown in perlformat, you have to use it with $^A (which you could also localize):
    formline( "@<< @<< @<<", '1', '2', '2' ); print "$^A\n";

    or specify an empty format before:

    format = . formline( "@<< @<< @<<", '1', '2', '2' ); write;

    Use a higher level format:

    format = @<< @<< @<< 1, 2, 2 . write;

    Or, switch to plain sprintf:

    say join ' ', map sprintf('%-3d', $_), 1, 2, 2;
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      lets say there are two fields, one of them is long and other one is small. Whats the ways to print all the contents

      $l = "This is long string" ; $s = "s"; format STDOUT = ~~ @<<< @< $l, $s .

      above is not working.

        As documented in perlform, ~~ should be used for changing values that finally become undefined.
        #!/usr/bin/perl use warnings; use strict; my @l = ('This is long string', 'Another long one'); my @s = ('s', 'S'); format = ~~ @<<<<<<<<<<<<<<<<<<< @< shift @l, shift @s . write;

        It's time you read the documentation again. I've never used formats in Perl, and I hope I never will; but I was able to put this together in one minute.

        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: formline, undefined format STDOUT
by kcott (Archbishop) on Apr 20, 2015 at 13:15 UTC

    Take a look at the documentation for formline.

    Note what it says about using double quotes. Your use of double quotes is very likely the cause of your problem.

    -- Ken

Re: formline, undefined format STDOUT
by toolic (Bishop) on Apr 20, 2015 at 13:12 UTC
Re: formline, undefined format STDOUT
by ikegami (Patriarch) on Apr 20, 2015 at 17:17 UTC
    Since you're just starting out with forms, you might want to consider using the far better Perl6::Form (Perl6-style forms for Perl5) instead.

      Or how about Mustache?

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
        That's a templating system, not a text formatter. It doesn't perform the same task at all.