
Iconx
Novice
Apr 16, 2014, 3:59 PM
Post #1 of 5
(32489 views)
|
Multiple hashes from module
|
Can't Post
|
|
Ok I'm back for another question, hopefully not so vague this time. I want to export multiple hashes and its not working, I can retrieve one(often not the one I want either) but not the other. Overview: - The perl module reads a directory of files and their contents and creates multiple hashes in different ways for different purposes. The perl file should be able to get both hashes. I've played around with Exporter with no luck. (Note: I've got the hashes declared within the subroutine and outside of it as well, not sure where it should be declared with how I'm calling it. Here's what I've got: ReadFile.pm --------------------------------------
package ReadFile; use strict; use File::Spec; use Data::Dumper; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw(%searchadmin_id %record); our ( %searchadmin_id, %record ); my $REC_DIR = '../accounts/'; sub Read_Active { our %record; our %searchadmin_id; # Read all files in directory an put in $files array if ( opendir( DIR, $REC_DIR ) ) { my @files = readdir(DIR); @files = File::Spec->no_upwards(@files); foreach my $file (@files) { chomp $file; #Read the lastline of each file and put in array my $filename = "$REC_DIR/$file"; ( open( my $IF, '<', $filename ) ); my @entry = <$IF>; close $IF; chomp $lastentry; my @record = split( ':', $lastentry ); my $mainid = $record[0]; my $uid = $record[1]; my $acct_name = $record[2]; my $type = $record[3]; my $org = $record[4]; my $admin_id = $record[5]; my $hashvars = ( "main_id => $mainid, uid => $uid, acctname => $acct_name, type => $type, org => $org, admin_id => $admin_id, ); #Hash Indexed by mainid %{ $record{$mainid} } = $hashvars; #Hash for admin_id = req (pending) %{ $searchadmin_id{$admin_id}{$mainid} } = $hashvars; } } return (\%searchadmin_id, \%record); } 1; pullaccts.pl -----------------
#!/usr/bin/perl use strict; use ReadFile qw(Read_Active); use Data::Dumper; my (%searchadmin_id, %record) = ReadFile::Read_Active(%record); print "--- Testing imported Hashes --- \n"; print Dumper(%searchadmin_id) ### This seems to be printing %record print Dumper(%record); ###This is printing nothing So what am I missing here? Iconx
|