http://www.perlmonks.org?node_id=302567


in reply to Re: Re: How's your Perl?
in thread How's your Perl?

If by a fix you mean sub bar {$bar[$_[0]]} $foo = *bar; $bar[1]="hi";, that does not work to the given spec.

Test it with print "yes" if \$foo->(1) eq \$foo->[1] and you see that it fails for me on 5.8.1. Get rid of the backslashes and it works, but the problem is that Perl's functions are pass by reference, return by value. Therefore the return of bar(1) is a new string with the same value as $bar[1], but you get something different by taking a reference to it.

Replies are listed 'Best First'.
Re: Re: Re: Re: How's your Perl?
by xmath (Hermit) on Oct 28, 2003 at 00:27 UTC
    ah yes, you're right.. it needs more than a one-char fix :-)

    the overall idea is still right though (as in, the correct solution is very similar to this), but I overlooked some details of your implementation