in reply to format characters

You can build your format template using formline and the accumulator $^A (see perlform and perlvar). But if it's just a typing laziness issue, get a decent editor. E.g. with vi, the sequence
o@<^[x50p

(^[ being the escape key) will result in a @ followed by fifty < chars:

@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: format characters
by mikejones (Scribe) on Feb 10, 2008 at 20:01 UTC
    I am trying what you suggested (and thank you!) but its not working. I want to replace this code:
    <snipped the _TOP> format STDOUT = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<< @<<<<<<< @<<<<<<<<<<<<< <<<<<<<<<< @||||||||||||||||||| @##.## $sfile, + $user, $grp, $gcos, dateme($mod,$mod2), $sz ~~ .

    with this code

    my $format = "format STDOUT = \n" . '@' . '<' x 125 . $sfile . q{ } . '@' . '<' x 8 . $user . q{ } . '@' . '<' x 8 . $grp . q{ } . '@' . '<' x 25 . $gcos . q{ } . '@' . '|' x 20 . dateme($mod,$mod2) . q{ } . '@' . '#' x 2 . '.##' . $sz . "\n" . "~~\n" . ".\n" ;

    And the errors I am getting are:

    Use of uninitialized value in concatenation (.) or string at find_hog. +tdy line 49. Use of uninitialized value in concatenation (.) or string at find_hog. +tdy line 49. Use of uninitialized value in concatenation (.) or string at find_hog. +tdy line 49. Use of uninitialized value in concatenation (.) or string at find_hog. +tdy line 49. Use of uninitialized value in localtime at find_hog.tdy line 105. Use of uninitialized value in concatenation (.) or string at find_hog. +tdy line 49. format STDOUT = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<< +@<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<< @||||||||||||||||||||19:00:00- +12/31/69 @##.## ~~ . Undefined format "STDOUT" called at find_hog.tdy line 227.

    Do I use a regular write? I am confused on how write knows about $format?

      I am trying what you suggested (and thank you!) but its not working.

      Huh? I didn't suggest that - I wrote about an editor (vi) command. But since you are bringing that up - re-read perlform, the chapter "Accessing Formatting Internals".

      If you construct your format into a string, you have to either eval it -

      my $format = '| @' . '>' x 10 . ' | ' . '@' . '<' x 10 . " |\n" . '$given, $surname' ."\n" . '.'; eval "format STDOUT = \n$format"; for ([qw(Bill Bruford)],[qw(Ginger Baker)]) { ($given, $surname) = @$_; write; } __END__ | Bill | Bruford | | Ginger | Baker |

      or use formline and the accumulator $^A :

      my $format = '| @' . '>' x 10 . ' | ' . '@' . '<' x 10 . " |\n"; for ([qw(Bill Bruford)],[qw(Ginger Baker)]) { formline( $format,@$_); print $^A; $^A = ''; } __END__ | Bill | Bruford | | Ginger | Baker |

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
        OK thank you much! I understand. So now I am asking

        1) Not sure why I am seeing 'Filename' and 'Owner' when print $^A is invoked. Can you see why?

        2) Is there a better way to line up my headings with the data then what I am doing? For example, q{ } x ##

        __OUTPUT__ REPORT OF .... on host: sparky Filename PageOwner 0 <snip> __END_OUTPUT__ my $fn = q<Filename> ; my $owr = q<Owner> ; my $go = q<GroupOwner> ; my $gc = q<Gecos> ; my $lmd = q<LastModifiedDate> ; my $smb = q<Size Mb> ; my $format_TOP = 'REPORT OF LARGE FILES on:' . "\n" . qx(hostname) . '@' . '<' x 12 . "\n\n\n" . 'Page' . '@' . '<' x 4 . "\n" . $% . "\n" . $fn . q{ } x 10 . $owr . q{ } x 6 . $go . q{ } x 1 . $gc . q{ } x 25 . $lmd . q{ } x 6 . $smb . "\n" . '=' x 8 . q{ } x 10 . '=' x 5 . q{ } x 6 . '=' x 10 . q{ } x 1 . '=' x 5 . q{ } x 25 . '=' x 16 . q{ } x 6 . '=' x 7 . "\n" ; formline( $format_TOP, $fn, $owr, $go, $gc, $lmd, $smb ) ; print $^A ; $^A = q{}; <snip>