In the immortal words of Strother Martin, "what we've got here is failure to communicate!"
Long ago and far away, the main thread began with a question about passing named parameters as hash key/value pairs: the key is the name and the value is the parameter.
Subsequently, in Re^3: Preferred technique for named subroutine parameters? and in the context, I thought, of the question of the main thread, akho wrote "Try using a reference as a hash key ... ".
I think this statement is the root of my confusion, because I would paraphrase it as "Try using a reference as the name of a named parameter", and I could not (and still cannot) understand why one would want to do this.
Further along in Re^3: Preferred technique for named subroutine parameters? and in sub-threads stemming therefrom, and in Re^5: Preferred technique for named subroutine parameters? in particular, there is discussion, as I understand it, of just what happens to a reference when it gets stringified as a hash key and of how to avoid the ill-effects of this process. But I still cannot answer what, to me, seems the Basic Question: Why would one want to use a reference as the name of a named parameter in the first place?
Until I can either answer the BQ or clear up any confusion I may have about akho's original statement, I fear I am doomed to endless, hopeless wandering... | [reply] |
For instance in functional programming anonymous functions are passed around, even in arrays or hashes and then you might even want to assign further data to them.
I never needed to do this, but it's certainly not useless to do so. You may want to read Higher Order Perl to learn more.
It wasn't clear that your problem is "what is it good for", you sounded more like "theres no difference".
| [reply] |
>perl -wMstrict -le
"my $funcs = [
sub { print q{i'm at index zero} },
sub { print q{and i'm at index 1} },
];
add_func({
fns => $funcs,
fn => sub { print q{i'm new here} },
at => 3
});
$funcs->[0]();
$funcs->[3]();
sub add_func {
my %args = %{ shift() };
$args{fns}->[$args{at}] = $args{fn}
}
"
i'm at index zero
i'm new here
It wasn't clear that your problem is "what is it good for", you sounded more like "theres no difference".
There is, indeed, a vast difference between passing a reference as a named parameter name (i.e., a hash key) and passing a reference as the parameter (i.e., hash value). My problem with passing a reference as a name was squarely in the "what's it good for" camp.
| [reply] [d/l] |