It's for both debugging and to clarify the output. Since this will go into a report, I'll need a lookup hash mapping the variable names with userfriendly descriptions, but initially, just the variable names should do.

I thought it might help if I posted my code, to show the context. Here it is:

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); }
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.

-- Burvil


In reply to Re^2: Print name of variable to STDOUT? by bowei_99
in thread Print name of variable to STDOUT? by bowei_99

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.