[boulder.pm] hash for multiple filehandles?
Robert L. Harris
Robert.L.Harris at rnd-consulting.com
Wed Jul 19 14:29:40 CDT 2000
What "print" doc? perldoc print? I'll check that when I get home.
For some ungodly reason, they refuse to let me put the perldoc, manpages, etc
on the boxes here.
Ok,
I changed to:
if ($Records{$RecNum}) {
print "\$Line :$Line:\n" if ($Records{$RecNum} eq "T");
print { $Handle{$i} } "$Line\n" if ($Records{$RecNum} eq "T");
}
Where $Records{} is "T" if I want this record dealt with. So if I get a
record nubmer 14, and I want it written out, it will be defined.
The above section gives me:
Use of uninitialized value at ./DefMungeSplit.pl line 222 (#2)
(W) An undefined value was used as if it were already defined. It was
interpreted as a "" or a 0, but maybe it was a mistake. To suppress this
warning assign an initial value to your variables.
Can't use an undefined value as a symbol reference at ./DefMungeSplit.pl line
222 (#3)
(F) A value used as either a hard reference or a symbolic reference must
be a defined value. This helps to delurk some insidious errors.
Uncaught exception from user code:
Can't use an undefined value as a symbol reference at ./DefMungeSplit.pl line 222.
main::PrintLine(01, '0007110000000000021277 ...') called at ./DefMungeSplit.pl line 471
main::DoMainWork('1277 ...') called at ./DefMungeSplit.pl line 170
I define with "my" and use strict much higher in the script. This is a very small
portion of the script. I do a "my ($i);" in the sub proc about 5 lines before
the foreach. Didn't think the my embeded would work. Is it better?
Thus spake Rob Nagler (nagler at bivio.com):
> Couple of points...
>
> The specific error is caused by the lack of braces (see "print" doc):
>
> Note that if you're storing FILEHANDLES in an array or other
> expression, you will have to use a block returning its value
> instead:
>
> print { $files[$i] } "stuff\n";
> print { $OK ? STDOUT : STDERR } "stuff\n";
>
> However, I don't understand how
>
>
> if ($Handle{$RecNum} eq "T") {
> print $Handle{$i} "$Line\n";
> }
>
>
> Will every be executed, because
>
> $Handle{$i}="OUT"."$i";
>
> Not sure what you want as the test case, but 'eq "T"' is probably not it.
>
> You should always use "my" and "use strict" imiho, e.g.
>
> foreach my $i (keys(%Records)) {
>
> I'm not sure what the first part:
>
> foreach my $i (keys(%Records)) {
> $Handle{$i}="OUT"."$i";
> open($Handle{$i}, ">$Out.$i") || die "Can't open Outputfile $Out.$i :$!:\n";
> }
>
> is doing, because you'll be overwriting the files in the second "foreach".
> Perhaps this is just test code.
>
> Hope this helps,
> Rob
:wq!
---------------------------------------------------------------------------
Robert L. Harris | Micros~1 :
Senior System Engineer | For when quality, reliability
at RnD Consulting | and security just aren't
\_ that important!
DISCLAIMER:
These are MY OPINIONS ALONE. I speak for no-one else.
FYI:
perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'
More information about the Boulder-pm
mailing list