Yes, yes and yes. Consider:

use strict; use warnings; my @servers; my %dataOptions = ( 1 => ['server', 'Server Name:', 1], 2 => ['dbType', 'Database Type:', 0], 3 => ['location', 'Server Location:', 0], 4 => ['function', 'Server Function:', 0], 5 => ['ip', 'Server IP:', 1], ); my %flowOptions = ( A => 'Add Another Server', C => 'Continue', D => 'Done', ); my %byType; addServer (\@servers); while (1) { #system ("clear"); printf " (%s) %s%-20s %s\n", $_, $dataOptions{$_}[2] ? '*' : ' ', @{$dataOptions{$_}}[1], $servers[-1]{$dataOptions{$_}[0]}, for sort keys %dataOptions; print '-' x 30, "\n"; printf " (%s) %s\n", $_, $flowOptions{$_} for sort keys %flowOpti +ons; print "Enter the number you would like to edit > "; chomp (my $choice = uc <STDIN>); if (exists $dataOptions{$choice}) { print "Please enter the ", $dataOptions{$choice}[1], ' '; chomp ($servers[-1]{$dataOptions{$choice}[0]} = <STDIN>); $byType{$dataOptions{$choice}[0]}{$#servers} = 1; } elsif (! exists $flowOptions{$choice}) { next; } last if $choice eq 'D'; # Can't add another unless all required data supplied for current +entry next if missingOptions (\%dataOptions, $servers[-1]); addServer (\@servers); } # Remove bogus last entry pop @servers if missingOptions (\%dataOptions, $servers[-1]); # later in the code for my $server (@servers){ print "Server $server->{server}\n"; } for my $serverIndex (sort keys %{$byType{ip}}) { print "Server $servers[$serverIndex]{server}: $servers[$serverInde +x]{ip}\n"; } sub addServer { my ($servers) = @_; push @$servers, {}; # Add a new entry $servers->[-1]{$dataOptions{$_}[0]} = '' for keys %dataOptions; } sub missingOptions { my ($options, $data) = @_; my @missing = grep {$options->{$_}[2] && ! length $data->{$options->{$_}[0]} +} keys %$options; return @missing; }

Prints:

(1) *Server Name: (2) Database Type: (3) Server Location: (4) Server Function: (5) *Server IP: ------------------------------ (A) Add Another Server (C) Continue (D) Done Enter the number you would like to edit > 1 Please enter the Server Name: server1 (1) *Server Name: server1 (2) Database Type: (3) Server Location: (4) Server Function: (5) *Server IP: ------------------------------ (A) Add Another Server (C) Continue (D) Done Enter the number you would like to edit > 5 Please enter the Server IP: 1.0.0.1 (1) *Server Name: (2) Database Type: (3) Server Location: (4) Server Function: (5) *Server IP: ------------------------------ (A) Add Another Server (C) Continue (D) Done Enter the number you would like to edit > a (1) *Server Name: (2) Database Type: (3) Server Location: (4) Server Function: (5) *Server IP: ------------------------------ (A) Add Another Server (C) Continue (D) Done Enter the number you would like to edit > 1 Please enter the Server Name: server2 (1) *Server Name: server2 (2) Database Type: (3) Server Location: (4) Server Function: (5) *Server IP: ------------------------------ (A) Add Another Server (C) Continue (D) Done Enter the number you would like to edit > 5 Please enter the Server IP: 0.1.1.0 (1) *Server Name: (2) Database Type: (3) Server Location: (4) Server Function: (5) *Server IP: ------------------------------ (A) Add Another Server (C) Continue (D) Done Enter the number you would like to edit > d Server server1 Server server2 Server server1: 1.0.0.1 Server server2: 0.1.1.0

True laziness is hard work

In reply to Re: Hash vs. Scalar+Text vs. DBD by GrandFather
in thread Hash vs. Scalar+Text vs. DBD by walkingthecow

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.