Path: utzoo!attcan!uunet!samsung!usc!apple!sun-barr!newstop!texsun!convex!convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: Implemented! (was Re: dynamic formats) Message-ID: <5250@convex.convex.com> Date: 7 Feb 90 21:08:47 GMT References: <5195@convex.convex.com> <1990Feb7.180424.2566@iwarp.intel.com> Sender: news@convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 60 In article <1990Feb7.180424.2566@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: >In article <5195@convex.convex.com>, tchrist@convex (Tom Christiansen) writes: >Is there anything wrong with setting $~ and $^ (for format and >top-of-page) as you need them? (Yup, helps to read the *whole* >manpage. :-) I've used $^ but had somehow missed $~. Sigh, this is as stupid as my flush() question. I honestly do like to find ways to do these things without modifying the language. Well, then, here's some tested code that seems to do the right thing. They're trivial examples but demonstrative. You could use indirection on names rather than pass-by-reference on the files if you wanted. I haven't tried pass-by-reference with the formats though. #!usr/bin/perl format FOO = home is @<<<<<<<<<<<<<<<<<<<<<<<< $ENV{'HOME'} . format BAR = @>>>>>>>>>>>>>>>>>>>>>>>> is home $ENV{'HOME'} . sub write { local(*FH, $FORM) = @_; local($oldFH) = select(FH); local($oldFORM) = $~; $~ = $FORM; write; select($oldFH); $~ = $oldFORM; } do write(*STDOUT,'FOO'); do write(*STDERR,'BAR'); do write(*STDOUT,'FOO'); do write(*STDERR,'BAR'); In fact, you could extend this using Vroman's write() subroutine so you could have a syntax of do write(*FH, 'formname', $var1, $var2, ...); if you knew ahead of time that the formats used @_ for their vars. --tom -- Tom Christiansen {uunet,uiucdcs,sun}!convex!tchrist Convex Computer Corporation tchrist@convex.COM "EMACS belongs in : Editor too big!"