Jenda has asked for the wisdom of the Perl Monks concerning the following question:
I've tried to use Lexical::Alias 0.03 because I'd like to be able to do something like:
but it seems Lexical::Alias doesn't work in subroutines. Is this a bug or the expected behaviour?sub foo { alias $_[0] => my $byRef; ... $byRef += $result; }
prints:use strict; use warnings; use Lexical::Alias; my $orig = 1; my $alias = 99; alias $orig => $alias; print "$orig = $alias\n"; sub foo { my $orig = 1; my $alias = 99; alias $orig => $alias; print "foo(): $orig = $alias\n"; } foo();
but I believe it should print:1 = 1 foo(): 1 = 99
1 = 1 foo(): 1 = 1
My Perl is
running under Win2k Server.This is perl, v5.8.0 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2002, Larry Wall Binary build 805 provided by ActiveState Corp. http://www.ActiveState. +com Built 18:08:02 Feb 4 2003
P.S.: IMHO, it would be better if the parameters to alias() were the other way around (I assign an alias to a variable, not a variable to an alias.) and if the alias was my()d automaticaly. So that I could write:
I think this would make more sense.sub foo { alias $byRef => $_[0]; ...
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Lexical::Alias & subroutines
by japhy (Canon) on May 19, 2003 at 13:41 UTC | |
by Jenda (Abbot) on May 19, 2003 at 14:52 UTC | |
by japhy (Canon) on May 19, 2003 at 15:07 UTC | |
by Jenda (Abbot) on May 19, 2003 at 15:14 UTC | |
by Aristotle (Chancellor) on May 21, 2003 at 11:59 UTC | |
| |
|
Re: Lexical::Alias & subroutines
by japhy (Canon) on May 19, 2003 at 14:08 UTC | |
|
Re: Lexical::Alias & subroutines
by BrowserUk (Patriarch) on May 19, 2003 at 13:05 UTC | |
by jdporter (Paladin) on May 19, 2003 at 13:17 UTC | |
by Jenda (Abbot) on May 19, 2003 at 15:09 UTC | |
by BrowserUk (Patriarch) on May 19, 2003 at 15:42 UTC | |
by Jenda (Abbot) on May 19, 2003 at 15:56 UTC | |
by BrowserUk (Patriarch) on May 19, 2003 at 17:08 UTC | |
|
Re: Lexical::Alias & subroutines
by halley (Prior) on May 19, 2003 at 12:25 UTC | |
by pfaut (Priest) on May 19, 2003 at 13:01 UTC |