I like Data::Alias
. It seems to be broken in 5.12. Can it be fixed? Will it be fixed soon? Is there any nice alternative?
相关问题
- $ENV{$variable} in perl
- Is it possible to pass command-line arguments to @
- Redirecting STDOUT and STDERR to a file, except fo
- Change first key of multi-dimensional Hash in perl
- How do I get a filehandle from the command line?
相关文章
- Running a perl script on windows without extension
- Comparing speed of non-matching regexp
- Can NOT List directory including space using Perl
- Extracting columns from text file using Perl one-l
- Lazy (ungreedy) matching multiple groups using reg
- How do I tell DBD::mysql where mysql.sock is?
- What is a good way to deploy a Perl application?
- Speeding up Selenium Webdriver
I just found another potential option:
Scalar::Alias
, which seems to work in Perl 5.12. Obviously, it only aliases scalars, but it doesn't require a fat comma in place of an equals sign.The module hasn't been updated since 2007 but you can always send a message to the author (Matthijs van Duin: xmath@cpan.org) or file a bug report as Robert mentioned in his answer.
Here are some alternatives:
As far as additional CPAN modules for aliasing that work in 5.12+:
And searching for 'alias' on CPAN turns up a few more, none seem to provide the "do everything with aliases in this statement" feature of Data::Alias though. So until
Data::Alias
is fixed, you can use one of the above, or the following pure Perl methods:Perl has built in support for aliasing any variable to variables that exist in the symbol table. This is done as follows:
But as always, be aware of what dynamic scope / local actually does before using it.
A lexical scalar can be used as an alias within the scope of a for loop:
this type of lexical alias can even be passed out of the loop in a closure if needed
You can create array aliases using Perl's aliasing magic for subroutine argument lists:
but that doesn't really give you any more functionality than references, just with a different syntax.
And an example using Perl's references:
Any version of
Data::Alias
built before Version 1.08 (Released October 22nd, 2010 BST) won't work with Perl 5.12 asData::Alias
prior to 1.08 is broken in Perl 5.12. Upgrade to the latest version (1.08 or newer) and it should work!As an interesting side note, it seems like being able to do aliases may be coming to Perl as a language feature in the future, with the cleanup of
:=
no longer meaning an empty attribute list. Look forward to it! :)