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

后端 未结 7 1941
走了就别回头了
走了就别回头了 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:31

    Uh... "passing hashes can only be done by reference"?

    sub foo(%) {
        my %hash = @_;
        do_stuff_with(%hash);
    }
    
    my %hash = (a => 1, b => 2);
    foo(%hash);
    

    What am I missing?

    I would say that if the issue is that you need to have multiple outputs from a function, it's better as a general practice to output a data structure, probably a hash, that holds everything you need to send out rather than taking modifiable references as arguments.

    0 讨论(0)
提交回复
热议问题