***** infoCopter.com/perl *****

Perl Formats - Reports

Implementation

Perl Formats - Reports

#!/usr/bin/perl -w
use strict;

use FileHandle;

#####  GLOBAL
$| = 1;
my $name = my $login = my $office = my $uid = my $gid = my $home = '';

open(OUTF, ">/tmp/test.txt") or die $!;
select(OUTF);

format OUTF_TOP =
                         Passwd File
 Name                Login    Office   Uid   Gid Home
 ------------------------------------------------------------------
.
format OUTF =
 @<<<<<<<<<<<<<<<<<< @||||||| @<<<<<<@>>>> @>>>> @<<<<<<<<<<<<<<<<<
 $name,              $login,  $office,$uid,$gid, $home
.


$name   = 'Reto M. Hersiczky';
$login  = 'foo';
$office = 'Uster';
$uid    = 471;
$gid    = 1234;
$home   = 'yourhome';
write;

$name   = 'bar';
$login  = 'yourlogin';
$office = 'Zürich';
$uid    = 47122;
$gid    = 654321;
$home   = 'myhome';
write;

close OUTF;

Output

[root@reto adm2002]# cat /tmp/test.txt
                         Passwd File
 Name                Login    Office   Uid   Gid Home
 ------------------------------------------------------------------
 Reto M. Hersiczky v   foo    Uster    471  1234 yourhome
 bar                 yourlogi Zürich 47122 65432 myhome
© reto :)