I have this code in my DrillPressTable.pl file:
#!/usr/bin/perl -w
use strict 'vars';
use VRML;
...
my $Dir="vrmlstuff";
my $Subdir="DrillPressTable";
my $LumberFile="$Dir/$Subdir/lumber.wrl";
&mystart($LumberFile,LF);
...
sub mystart {
my($file,$fh)=@_;
open($fh,"> $file")
|| die("ERROR: Unable to open $file for output");
my @lines=split(/\n/,<<END);
#VRML V2.0 utf8
NavigationInfo { headlight TRUE }
DirectionalLight { # First child
direction 0 0 -1 # Light illuminating the scene
}
END
my $i=0;
if($i==0) {
foreach my $line (@lines) {
print $fh "$line\n";
}
} elsif($i==1) {
&myprint(\@lines,$fh);
} elsif($i==2) {
&printout(\@lines,$fh);
}
} # end mystart
...
sub myprint(
my($lines,$fh)=@_;
foreach my $line (@{$lines}) {
print $fh "$line\n";
}
} # End myprint;
file VRML.pm contains this code:
package VRML;
BEGIN {
@EXPORT = qw(... &printout ...);
}
use strict 'vars';
...
sub printout {
my($lines,$fh)=@_;
$fh=STDOUT unless($fh);
foreach my $line (@{$lines}) {
print $fh "$line\n";
}
} # End printout;
If I set $i=0 or 1 in subroutine mystart it works perfectly, and the
proper lines are written to lumber.wrl. But if I set $i=2 I get this
error message:
print() on unopened filehandle LF at .../VRML.pm line 2886
Line 2886 in VRML.pm is in printout; the line is:
print $fh "$line\n";
How do I declare $fh in subroutine printout so it recognizes the intended
filehandle?
-
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.
|