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:
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 arraysmy $array->[0] = $arg{key1}; my $key->[0] = 'key1' if ($array->[0]);
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:
sometimes user can pass only one variable to the _sub(). for examplesub _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}; ... }
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_sub(key3 => 'big-mama');
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: how to split hash into two arrays
by Your Mother (Archbishop) on Jul 07, 2009 at 08:00 UTC | |
Re: how to split hash into two arrays
by missingthepoint (Friar) on Jul 07, 2009 at 08:04 UTC | |
Re: how to split hash into two arrays
by Anonymous Monk on Jul 07, 2009 at 08:00 UTC | |
Re: how to split hash into two arrays
by grizzley (Chaplain) on Jul 07, 2009 at 11:42 UTC |
Back to
Seekers of Perl Wisdom