in reply to Re: Print name of variable to STDOUT?
in thread Print name of variable to STDOUT?
I thought it might help if I posted my code, to show the context. Here it is:
As you can see, it returns an array of hash of hashes. To avoid unnecessary complexity, I want to avoid putting it in one big hash, with keys 'who', 'from', and 'ftp'. Can I tell perl to output the variable names %lkup_by_who, \%lkup_by_from, \%lkup_by_ftp? I know that these variables are only defined within the subroutine, and so I'd have to put it in one big hash or print the information within the subroutine for it work.sub GetStats { my $ref_files = shift @_; my (%lkup_by_who, %lkup_by_how, %lkup_by_from, %lkup_by_ftp); foreach my $file (@$ref_files) { open "LAST", "<", $file or croak "Cannot open file $file - $!\n"; print "Reading file $file ... \n"; while (<LAST>) { my ($who, $how, $from, @junk) = split (/\s+/); next if (!$who or !$how or !$from); next if (/wtmp begins/); if ($how eq "console") { $how = $from; next; } $from =~ s/:\d+(\.\d+)?//g; $lkup_by_who{$file}{"$who"}++; $lkup_by_from{$file}{"$from"}++; if ($how eq "ftp") { $lkup_by_ftp{$file}{"$who"}++; } } close (LAST); } return (\%lkup_by_who, \%lkup_by_from, \%lkup_by_ftp); }
-- Burvil
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Print name of variable to STDOUT?
by GrandFather (Saint) on Aug 08, 2006 at 22:58 UTC |