Why not either a hash of hash or array of hash for the commands?

Use a hash of hash if each command is unique where the command name (eg 'addTargetServer') is the top level key. Use an array of commands if the order is important or there may be multiple commands with the same name. Add a 'cmdName' key to the command hashes in the AoH case.

Something like the following code may be what you are after. Given the command line -u USER -p PASSWORD cmdName=addTargetServer hostname=host123 ipAddress=1.1.1.1 cmdName=subTargetServer hostname=host321 ipAddress=1.1.1.2, the following:

use warnings; use strict; use Getopt::Long; use Data::Dump::Streamer; my %options; Getopt::Long::GetOptions (\%options, "u=s", "p=s"); print "Option $_: value %options{$_}\n" for keys %options; my @commands; my $entry; for (@ARGV) { next unless /(\w+)=(.*)/; $entry = \%{$commands[scalar @commands]} if $1 eq 'cmdName'; $entry->{$1} = $2; } print "\n"; for my $command (@commands) { print join "\n", (map {"$_ = $command->{$_}"} sort keys %$command) +, "\n"; }

prints:

Option p: value %options{p} Option u: value %options{u} cmdName = addTargetServer hostname = host123 ipAddress = 1.1.1.1 cmdName = subTargetServer hostname = host321 ipAddress = 1.1.1.2

DWIM is Perl's answer to Gödel

In reply to Re: how to get name of hash value itself? by GrandFather
in thread how to get name of hash value itself? by Binford

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.