http://qs321.pair.com?node_id=777777

baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:

hi,

i need a quick oneliner for this script if one exists:

my $array->[0] = $arg{key1}; my $key->[0] = 'key1' if ($array->[0]);
so basically i have a hash that needs to be broken into two arrays and depending on a hash key the position of the key and value needs to be placed on a specific position in two corresponding arrays

thank you

Update:

ok i have a sub() that takes some variables. and the way to pass some variables to that sub is through hash interface.like this:

sub _sub { my %arg = @_; my $array; # sometimes is treated as a scalar $array->[0] = $arg{key1}; $array->[1] = $arg{key2}; $array->[2] = $arg{key3}; $array->[3] = $arg{key4}; ... }
sometimes user can pass only one variable to the _sub(). for example
_sub(key3 => 'big-mama');
in this case only the $array->[2] will be defined and all others will be undef. so what i need is one extra array that will tell me the key (key3) that corresponds to that variable and that key should be placed on a $secarray->[2] position