Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li><p>first change your definition of <code>do_function</code> to:</p> <pre><code>sub do_function { my $fn = shift; goto &amp;{$functions-&gt;{$fn}} } </code></pre> <p>that is the proper way to dispatch to a new subroutine. this form of <code>goto</code> replaces the currently executing subroutine with the new coderef, passing <code>@_</code> unchanged, and removing <code>do_function</code> from the call stack (so <code>caller</code> works right). you probably want some error checking in there too, to make sure that <code>$fn</code> is a valid name.</p></li> <li><p>inside your function, you can simply modify cells of <code>@_</code> directly, and you do not need to pass anything by reference (since perl already did that for you).</p> <pre><code>sub add1 {$_[0]++} my $x = 1; add1 $x; say $x; # 2 </code></pre> <p>to support <code>key =&gt; value</code> arguments without passing by reference you could write it this way:</p> <pre><code>in $functions-&gt;{f1}: my %args; while (@_) { $args{$_} = /errs/ ? \shift : shift for shift } ## process data ... ## alter ${$args{errs}} ## ... </code></pre></li> <li><p><strong>HOWEVER</strong> since in your case <code>$errs</code> is a hash reference, you don't need to do any extra work. all references are passed by reference automatically. in your existing code, all you have to do is modify a key of <code>$args{errs}</code> (as you are doing right now) and it will modify every reference to that hash.</p> <p>if you wanted a function local hash, you need to make a copy of the hash*:</p> <pre><code>my %errs = %{$args{errs}}; </code></pre> <p>where <code>%errs</code> is private, and once you are done, you can push any values you want to make public into <code>$args{errs}</code> with <code>$args{errs}{...} = ...;</code>. but be sure not to replace <code>$args{errs}</code> with the copy (as in <code>$args{errs} = \%errs</code>) since that will break the connection to the caller's error hash. if you want to copy all the new values in, you could use one of: </p> <pre><code>%{$args{errs}} = %errs; # replace all keys @{$args{errs}}{keys %errs} = values %errs; # replace keys in %errs ... and $args{errs}{$_} = $errs{$_} for keys %errs; # conditional replace </code></pre> <p>*or localize some/all of the keys</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload