[comp.lang.perl] Variable output formats

worley@compass.com (Dale Worley) (12/13/90)

To get a variable output format, you have to construct the format
definition as a string and 'eval' it.  For instance,

    $myformat = '@<<<<<<<@<<<<<<<<<<<<@<<<<<<<<<<<<@<<<<<<<<<<<@<<<<<<<<<<';

    eval "
    format STDOUT = 
    $myformat
    \$ARGV[0],\$ARGV[1],\$ARGV[2],\$ARGV[3],\$ARGV[4]
    .
    ";

    write STDOUT;

If you run this program, it prints its first five arguments with the
format in $myformat.

(Remember that the final '.' must be followed by a newline, or the
format definition is syntactically invalid and will not take effect.)

Dale

Dale Worley		Compass, Inc.			worley@compass.com
--
It's okay to crave approval ... isn't it?