in reply to Creating a dynamic hash from an array
Not to take anything away from Athanasius post, but being Perl, timtowtdi :) Here's another potential solution.
Instead of looking at it like you have to transform the array into key/value pairs in the hash, you can simply throw the array into the hash directly:
my $tmp = { NameTag => $nametag, Name => $name, Params => \@params, };
Then:
sub CreateString { ( my $self, my $hash ) = @_; my $str = "A|" . $hash->{'NameTag'} . "|"."Command"."|" . $hash->{'Name'} . "|" . join( "|", @{ $hash->{ Params } } ); return ($str); }
Update: In fact, you can also eliminate the need for the $tmp var entirely by calling your sub like this:
my $InputRequest = $Obj->CreateString({ NameTag => $nametag, Name => $name, Params => \@params, });
|
|---|