in reply to Re: Re: Lexical::Alias & subroutines
in thread Lexical::Alias & subroutines

In your first example

sub foo { my $x = $_[0] eq 'whatever' ? $_[1] : $_[2]; ... }

Seems just as effective. But in your second, I agree. I've looked enviously at the perlsub examples of using globs to avoid the need to dereference refs and wished for a way to do the same thing with lexicals. Maybe Diotalevi's Lexical::TypeGlob would work for that? I haven't gotten around to playing with it yet.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

Replies are listed 'Best First'.
Re: Re: Re: Re: Lexical::Alias & subroutines
by Jenda (Abbot) on May 19, 2003 at 15:56 UTC

    But it is not the same. Your code creates a copy. So the changes to $x do not affect the parameters to foo().

    Lexical::TypeGlob doesn't seem to be related.

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

      Right you are. I'm not having a good thread am I.

      Maybe this will make up for it -- but then again...

      #! perl -slw use strict; sub doit{ our $scalar; local *scalar = ($_[0] eq 'first' ? \$_[1] : \$_[2]); $scalar = 'new value'; } sub double'em{ our @array; local *array = $_[0]; $_ *= 2 for @array; } my ($x, $y) = ('old value') x 2; doit 'first', $x, $y; print "$x, $y"; my @a = 1 .. 10; double'em \@a; print "@a"; __END__ D:\Perl\test>temp new value, old value 2 4 6 8 10 12 14 16 18 20

      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller