sloppyhack
Technical User
I have been trying to get a file into memory to using in processing data. Here is my sample code.
opendir (INPUT3, "/GHX Data Processing/Reference Files/AllSource Export/"
@allexport = readdir INPUT3;
closedir INPUT3;
foreach $allexport (@allexport) {
if ($allexport =~ /\.txt/) {
open (ALLSOURCE, "/GHX Data Processing/Reference Files/AllSource Export/$allexport" || warn "cannot open AllSource Export File: $!"; #open AllSource export
my @allkeys;
my @alldata;
while (<ALLSOURCE>) {
chomp;
my @fields = split /\t/;
if ($. == 1) {
@allkeys = @fields;
next;
}
my %allhash = ();
@allhash{@allkeys} = @fields;
push @alldata, \%allhash;
}
}
}
print "$#alldata"; #prints -1
print "$alldata[34]{'OrgID'}"; #I know this value exists on this line of the source file but prints nothing
I am certain the hash is being set up properly. I am either pushing the hash into the array incorrectly or calling to the array incorrectly.
PLEASE HELP!!! This is driving me nuts.
Bryant
Boulder CO
opendir (INPUT3, "/GHX Data Processing/Reference Files/AllSource Export/"
@allexport = readdir INPUT3;
closedir INPUT3;
foreach $allexport (@allexport) {
if ($allexport =~ /\.txt/) {
open (ALLSOURCE, "/GHX Data Processing/Reference Files/AllSource Export/$allexport" || warn "cannot open AllSource Export File: $!"; #open AllSource export
my @allkeys;
my @alldata;
while (<ALLSOURCE>) {
chomp;
my @fields = split /\t/;
if ($. == 1) {
@allkeys = @fields;
next;
}
my %allhash = ();
@allhash{@allkeys} = @fields;
push @alldata, \%allhash;
}
}
}
print "$#alldata"; #prints -1
print "$alldata[34]{'OrgID'}"; #I know this value exists on this line of the source file but prints nothing
I am certain the hash is being set up properly. I am either pushing the hash into the array incorrectly or calling to the array incorrectly.
PLEASE HELP!!! This is driving me nuts.
Bryant
Boulder CO