Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: how to manage a large console menu

by liverpole (Monsignor)
on May 22, 2006 at 14:06 UTC ( [id://550937]=note: print w/replies, xml ) Need Help??


in reply to Re^2: how to manage a large console menu
in thread how to manage a large console menu

Yes, that's a valid point.  I considered using a hash in my example, but decided against it for the reason that, in this particular case, it's pretty easy to make the transformation from 'systemN' to 'hostname_to_systemN' for any value of N.

The potential downside to making it a hash is that you have to sacrifice keeping it in the order you like (unless order isn't important, or you don't mind just using the order which sort generates).

Another option which lets you keep the order you prefer, and still have corresponding values for each of your "keys" would be to have both an array *and* a hash, eg.:

my @systems = qw( this_system_should_be_first system1 system2 system3 the_final_system ); my %systems = ( this_system_should_be_first => 'hostname_to_first_system', system1 => 'hostname_to_system1', system2 => 'hostname_to_system2', system3 => 'hostname_to_system3', the_final_system => 'hostname_to_final_system', );
which gives a nice flexibility, but requires making updates in two data structures rather than just one.

The tradeoff one chooses will ultimately be a matter of personal preference and/or need.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^4: how to manage a large console menu
by BUU (Prior) on May 22, 2006 at 19:44 UTC
    For slightly less redundancy, how about:
    my @systems = ( [ system1 => host_1 ], [ system2 => host_2 ], [ system3 => host_4 ], #etc );
Re^4: how to manage a large console menu
by parv (Parson) on May 22, 2006 at 20:05 UTC
    my @systems = qw( this_system_should_be_first system1 ... ); my %systems = ( this_system_should_be_first => 'hostname_to_first_system', system1 => 'hostname_to_system1', ... );
    Too much typing there, use hash slice man (after populating "@systems") ...
    my %systems; @{ @systems } = qw( hostname_to_first_system hostname_to_system1 ... ) ;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://550937]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-03-28 19:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found