My first thought is do something like this:
I do not like the call syntax I am left with:package snafu; sub foo { my $bar = shift; # Interesting things happen $$bar = $baz; if ( $things_worked ) { return SUCCESS_CODE; else { return FAILURE_CODE; } }
because I find the extra slash somewhat jarring - it breaks the flow of the code.unless ( $fsck->foo(\$variable) == SUCCESS_CODE ) { die "That was quite grim"; }
The other way I know of doing pass-by-reference in perl is like this:
It gives me a nicer calling syntaxpackage snafu; sub foo { # interesting things happen $_[0] = $baz; if ( $things_worked ) { return SUCCESS_CODE; else { return FAILURE_CODE; } }
but I cannot help feeling that the @_ trick is somehow evil and not a very nice thing to do to a variable.unless ( $fsck->foo($variable) ) { die "A terrible way to go"; }
Is there a preferred way of doing this? In the experience of the other Monks, which makes more sense? Is the @_ trick really an evil thing or am I being squeamish? Have I missed something obvious?
TIA,
mikfire
In reply to Pass by reference: is it good form to grope @_? by mikfire
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |