in reply to Re^5: how to let sub return hash of 2 sub?
in thread how to let sub return hash of 2 sub?
Hello dear Ikegami, hello dear people,
Dear Ikegami, bag your pardon, as I mitght possibly read wrong, you named different things. First time you wrote: Re: how to let sub return hash of 2 sub?
objectA.pm
sub parameter { ... return map { NameValTuple->new( name => $_, val => $rv{$_} } keys(% +rv); }
But map if I'm thinking right returns an array, does'nt it? That is not 100% exactly what I need.
Second time you wrote: Re^3: how to let sub return hash of 2 sub?
sub parameter { ... return NameValTuple->new( name => $name, val => $val ); }
.. which I am unsure what it does exactly. There are the 2 scalars $name and $val. But I think I need really two subs in the returned object.
Now as I see, you write the same as second time. Okay so far.
I have tried to guess, what you have meant to do. This is my solution with a little change at all.
package objectA; sub new { my $class = shift; my $self = {}; bless $self, $class; return $self; } sub map_query { my $self = shift; my $hash = shift; map { $self->{ values }->{ $_ } = $$hash{ $_ }; } keys %{ $hash }; } sub parameter { my $self = shift; my $para = shift; print "__ parameter para[$para] \n"; my $param = $para =~ m/^([^\.]*\.)(.*?)$/i ? $2 : $para; print "__ parameter param[$param] - val[$self->{ values }->{ $p +ara }]\n"; return NameValTuple->new( $param, $self->{ values }->{ $para } ); } package NameValTuple; sub new { my $class = shift; my $self = { _key => shift, _val => shift || '', }; bless $self, $class; print ">> NameValTuple new key[$self->{_key}] val[$self->{_val +}]\n"; return $self; } sub name { my $self = shift; return $self->{_key}; } sub val { my $self = shift; return $self->{_val}; } 1;
As you might have seen allready, I do not simple want the key and the value but have to change the key in this way, that instead of the key I have to return the key without the leading word plus dot.
This seams to work now, together with the former listed testpar.pl Re^2: how to let sub return hash of 2 sub?
Thanks to you all, Have A Nice Day, Thomas
|
|---|