J
Jürgen Exner
ela said:Previously, George has kindly designed and revised codes for "voting" the
most representative candidate from __DATA__ below. His initial design is to
separate subroutines query and ReadData, but as a file of million rows is to
read, I tried to embed subroutine query into ReadData but failed. There are
two problems (relevant lines marked with *************).
1) While $a[0] is printed as '02', I don't know why it can't be passed into
subroutine successfully
2) When the subroutine query is called inside subroutine ReadData, error
message "Can't coerce array into hash" will prompt during execution. In the
debug process, I hardcode it to "01" but in real case I wanna pass a[0] as
argument. The strange point is, if I pass a[0], the error message won't
prompt but still nothing is to print out.
You are missing
use strict; use warnings;
Had you done so then perl would have told you:
Global symbol "$firsttime" requires explicit package name at C:\tmp\t.pl
line 5.
Global symbol "$pre_a" requires explicit package name at C:\tmp\t.pl
line 6.
Global symbol "@a" requires explicit package name at C:\tmp\t.pl line 9.
Global symbol "$thr" requires explicit package name at C:\tmp\t.pl line
9.
Global symbol "$thr" requires explicit package name at C:\tmp\t.pl line
11.
Global symbol "$pre_a" requires explicit package name at C:\tmp\t.pl
line 34.
Global symbol "$pre_a" requires explicit package name at C:\tmp\t.pl
line 35.
Global symbol "$firsttime" requires explicit package name at C:\tmp\t.pl
line 36
..
Global symbol "$thr" requires explicit package name at C:\tmp\t.pl line
37.
Global symbol "$firsttime" requires explicit package name at C:\tmp\t.pl
line 40
..
Execution of C:\tmp\t.pl aborted due to compilation errors.
I would suggest to fix those first and then ask again.
Furthermore the indentation of your code is -shall we say- imaginative,
making it very hard to read your code.
my @col;
my %data;
$firsttime = 1;
$pre_a = "dummy";
ReadData();
$_ = query($a[0],$thr); # *************
However it appears to me that you didn't declared nor defined @a
anywhere on this level. Of course I may be mistaken, it is difficult to
tell what is top level code and what are subs because of poor
indentation.
jue