Hello monks,

I have a simple command line menu when my script starts up. The menu is quite easy, but I am trying to figure out the best way to store the data. Here's an example (in the actual code there are 15 items per server):

my ($server,$db_type,$server_location,$server_function); my @servers; while (1) { system("clear"); print "\t\t\tPLEASE CHOOSE AN OPTION FROM BELOW\n"; print <<EOF; (1) Server Name: $server (2) Database Type: $db_type (3) Server Location: $server_location (4) Server Function: $server_function ------------------------------------------- (A) Add Another Server (C) Continue (D) Done * - item is optional. EOF print "Enter the number you would like to edit > "; chomp( my $choice = <STDIN> ); if ( $choice == 1 ) { print "Please enter the server name: "; chomp( $server = <STDIN> ); } elsif ( $choice == 2 ) { print "Please enter the database type: "; chomp( $db_type = <STDIN> ); } elsif ( $choice == 3 ) { print "Please enter the server location: "; chomp( $server_location = <STDIN> ); } elsif ( $choice == 4 ) { print "Please enter the server function: "; chomp( $server_function = <STDIN> ); } elsif ( $choice =~ /a/i ) { push(@servers,"$server,$db_type,$server_location,$server_f +unction); $server=""; $db_type=""; $server_location=""; $server_function=""; } elsif ( $choice =~ /c/i ) { push(@servers,"$server,$db_type,$server_location,$server_f +unction); last; } else { next; } } ..... # later in the code for my $server (@servers) { my ($server,$db_type,$server...)=split(',',$server); do stuff; }


My question:
Is there a better way that this can be done, so that later the server data can be looked up by hostname or ip? Is there a better way to do the menu? This way just seems terrible.

In reply to 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.