in reply to Re: formline, undefined format STDOUT
in thread formline, undefined format STDOUT

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.

Replies are listed 'Best First'.
Re^3: formline, undefined format STDOUT
by choroba (Cardinal) on Apr 20, 2015 at 15:17 UTC
    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.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Thnx for your help, this is what I was looking for :

      #!/usr/bin/perl use warnings; use strict; my @row; my @f_map = ('f1', 'f2'); my $f = "format = \n" . ('^' . '<' x 15 . '|') x scalar(@f_map) . "\n" . '@row' . "\n" . ('^' . '<' x 15 . '|') x scalar(@f_map) . "~~\n" . '@row' . "\n" . ".\n"; eval($f); # @row = ('blah1' x 10, 'blah2' x 10); write;

      output :

      blah1blah1blah1b|blah2blah2blah2b| lah1blah1blah1bl|lah2blah2blah2bl| ah1blah1blah1bla|ah2blah2blah2bla| h1 |h2 |