Untested, but lots of stuff fixed. Changes marked with "!!!!"
#!/perl/bin/perl # !!!! Especially when learning, you should use these: use strict; use warnings; sub adduser{ print "\nI am in the adduser array now"; } #create the array my @data = ( { query => 'First Name',}, # !!!! Removed "{ query => 'Firt Name', }," { query => 'School', }, { query => 'Phone', }, { query => 'Position', }, { query => 'Role', }, ); MAIN_LOOP: while (1) { #greeting system("cls"); print "iT For Dominica User Database:\n", "Enter the Number then enter the value.\n"; #number the amt of items in list # !!!! Much easier to read: for my $i (0 .. $#data) { print "\t", $i+1, ". ", $data[$i]{query}, ": ", $data[$i]{value} || "", "\n"; } print "\t0. Done\n"; # !!!! Added loop to simplify error handling. foreach ('once') { print "Type a number to choose to change: "; my $number = <STDIN>; chomp($number); if ($number eq "" || $number eq "0") { last MAIN_LOOP; } # !!!! Make sure it's a number! # !!!! Removed hardcoded "6". if ($number =~ /[^0-9]/ || $number > @data ) { print("Bad input!"); redo; # Ask again. } } --$number; print "\n\nPlease enter your ", $data[$number]{query}, ": "; chomp($data[$number]{value} = <STDIN>); } # !!!! Still don't know what this adduser stuff is suppose to do. # !!!! Cleaned up this loop. foreach my $field (@data) { my $query = $field->{query}; my $value = $field->{value}; if (defined($field->{value}) && $field->{value} ne "") { print("$query: $value\n"); } }

In reply to Re^3: Testing Hash Arrays by ikegami
in thread Testing Hash Arrays by Snowman11

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.