I've tried to use Lexical::Alias 0.03 because I'd like to be able to do something like:

sub foo { alias $_[0] => my $byRef; ... $byRef += $result; }
but it seems Lexical::Alias doesn't work in subroutines. Is this a bug or the expected behaviour?
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();
prints:
1 = 1 foo(): 1 = 99
but I believe it should print:
1 = 1 foo(): 1 = 1

My Perl is

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
running under Win2k Server.

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:

sub foo { alias $byRef => $_[0]; ...
I think this would make more sense.

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


In reply to Lexical::Alias & subroutines by Jenda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.