Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

None of the suggestions have worked, but I found a solution. In my VRML.pm file, in any subroutine printing output, I added a myprint argument and where the subroutine originally invoked &printout, I changed it to invoke \&myprint, where @lines is an array of lines to be printed:

sub egg { # prints a 3d egg. my %args=(myprint => \&printout, xaxis => 10, ...); # Produces lines of wrl output in @lines ... $myprint=$args{myprint}; &{$myprint}(\@lines); }

In DrillPressTable.pl, which uses VRML.pm, I added a global $Fh, and changed the invocation of mystart, and its code, and myprint's code as well:

my $Fh; # w/b set in mystart. &mystart($LumberFile,LF); sub mystart { my($file,$fh)=@_; open($fh,"> $file") || die("ERROR: Unable to open $file for output"); $Fh=$fh; my @lines=split(/\n/,<<END); #VRML V2.0 utf8 NavigationInfo { headlight TRUE } ... END &myprint(\@lines); } sub myprint { my($lines)=@_; foreach my $line (@{$lines}) { print $Fh "$line\n"; } }

So now in DrillPressTable.pl I can direct lines of output to multiple file handles, and I don't need to change any of the 70-odd perl programs that use my VRML.pm. They'll just take the default of &printout, which prints to STDOUT, just like before.


In reply to Re^2: Filehandle in subroutine in use VRML.pm by smittypaddler
in thread Filehandle in subroutine in use VRML.pm by smittypaddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-03-28 20:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found