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


In reply to Re^6: how to let sub return hash of 2 sub? by toohoo
in thread how to let sub return hash of 2 sub? by toohoo

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.