What's the best Perl practice for returning hashes from functions?

后端 未结 7 1938
走了就别回头了
走了就别回头了 2021-02-04 07:31

I am mulling over a best practice for passing hash references for return data to/from functions.

On the one hand, it seems intuitive to pass only input values to a fun

7条回答
  •  北海茫月
    2021-02-04 08:23

    If it's getting complicated enough that both the callsite and the called function are paying for it (because you have to think/write more every time you use it), why not just use an object?

    my $results = $this->getData('input');
    
    $results->key_value_thingies;
    $results->listy_thingies;
    

    If making an object is "too complicated" then start using Moose so that it no longer is.

提交回复
热议问题