alan@tkna.tkna.com (Alan Light) (12/12/90)
I can't seem to use a variable to specify an output format picture. Consider the following code: $myformat = '@<<<<<<<@<<<<<<<<<<<<@<<<<<<<<<<<<@<<<<<<<<<<<@<<<<<<<<<<'; format STDOUT = $myformat $_[0],$_[1],$_[2],$_[3],$_[4] . It seems that the string "$myformat" is included verbatim in the output picture. I'm running perl 3.0 PL 12 -- _______________________________________________ Alan Light uunet!tkna!alan Telekurs (North America), Inc. New York, NY.
tchrist@convex.COM (Tom Christiansen) (12/12/90)
In article <1990Dec11.221304.2933@tkna.uucp> alan@tkna.tkna.com (Alan Light) writes:
:I can't seem to use a variable to specify an output format picture.
:Consider the following code:
:$myformat = '@<<<<<<<@<<<<<<<<<<<<@<<<<<<<<<<<<@<<<<<<<<<<<@<<<<<<<<<<';
:format STDOUT =
:$myformat
:$_[0],$_[1],$_[2],$_[3],$_[4]
:.
:It seems that the string "$myformat" is included verbatim in the output
:picture.
That's right -- this is how formats work. They alternate lines of
literal descriptions with variable references.
:I'm running perl 3.0 PL 12
Wow, that's ancienct history. Seems to be what I'm about to suggest
doesn't work back then. If you were up to the current (or at least
a more recent) patchlevel, you could use an eval:
$myformat = '@<<<<<<<@<<<<<<<<<<<<@<<<<<<<<<<<<@<<<<<<<<<<<@<<<<<<<<<<';
eval <<EOS;
format STDOUT =
$myformat
\$_[0],\$_[1],\$_[2],\$_[3],\$_[4]
.
EOS
--tom
--
Tom Christiansen tchrist@convex.com convex!tchrist
"With a kernel dive, all things are possible, but it sure makes it hard
to look at yourself in the mirror the next morning." -me
markb@agora.uucp (Mark Biggar) (12/14/90)
In article <1990Dec11.221304.2933@tkna.uucp> alan@tkna.tkna.com (Alan Light) writes: >I can't seem to use a variable to specify an output format picture. >Consider the following code: > >$myformat = '@<<<<<<<@<<<<<<<<<<<<@<<<<<<<<<<<<@<<<<<<<<<<<@<<<<<<<<<<'; > >format STDOUT = >$myformat >$_[0],$_[1],$_[2],$_[3],$_[4] >. Perl things its a variable line not a format line. To get what you want warp the format in an eval like so: eval <<EOFORMAT format STDOUT = $myformat \$_[0],\$_[1],\$_[2],\$_[3],\$_[4] . EOFORMAT -- Perl's maternal uncle Mark Biggar