Dear fellow monks, your novice here.
I am trying to understand what goes on behind the scenes with the code posted below.
I keep getting
Use of uninitialized value in print at map001.pl line 61. (and at line 81)
How do I get the code to tell me the names of the key - value pairs so that I can reference them ?
# Perl program to demonstrate the # splitting into the hash #!/usr/bin/perl use strict; use warnings; # variables used for computations my $linecount; my $start = time; my $column_count; my $file_errors = 0; my %distance; my %consec_two; my %consec_three; my %adj_row; my @prev; #----------------------------------------------------- my @items = (2,14,7,17,1,12,3,4,11,5,13,6,8,10,9,16,15,18); print "@items\n\n"; my @wrongsort = sort @items; print "@wrongsort\n\n"; @items = map {sprintf '%02u', $_ } @items; print "@items\n\n"; @items = sort @items; print "@items\n\n\n"; $column_count = @items; my ($odd)=(0); my ($even)=(0); print "Column Count = ","$column_count\n"; map {$_ % 2 ? $odd++ : $even++} @items; print "Odd = ","$odd\n"; print "Even = ","$even\n"; print "\n\n"; my %odd_even; print "\%odd_even hash contents \t\t", %odd_even, "\n\n"; + $odd_even{"$odd $even"}++; print "\%odd_even hash contents \t\t", %odd_even, "\n\n"; print "\%odd_even contents \t\t", $odd_even{0}, "\n\n"; # compute average for each row # first adding them all my %average; my $sum; map {$sum += $_} @items; my $avg = $sum / @items; $avg = ($avg - int($avg)) >= 0.5 ? int($avg) + 1 : int($avg); $average{$avg}++; print "AVERAGE hash contents \t\t", %average, "\n\n"; print "AVERAGE hash contents \t\t", $average{0}, "\n\n";

thankyou

In reply to How to get the key - value names from a hash by Scotmonk

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.