How can I get a working Data :: Alias ​​in Perl 5.12?

I like Data::Alias . It seems to be broken in 5.12. Can this be fixed? Will this be fixed soon? Is there a good alternative?

+4
source share
3 answers

Any version of Data::Alias created before version 1.08 (released October 22, 2010 by BST) will not work with Perl 5.12, because Data::Alias prior to 1.08 is broken in Perl 5.12. Upgrade to the latest version (1.08 or later) and it should work!

As an interesting note, it seems that the ability to do aliases may appear in Perl as a language function in the future, with the cleanup := no longer means an empty list of attributes . Looking forward to it!:)

+10
source

The module has not 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 said in his answer.

Here are a few alternatives:

  • As for the additional CPAN modules for aliases that work in 5.12 +:

    And the search for an “alias” on the CPAN appears a few more, however, none of them indicates the function “do everything with the help of aliases in this expression“ Data :: Alias. Thus, until Data::Alias is fixed, you can use one of the above or the following pure Perl methods:

  • Perl has built-in support for smoothing any variable in variables that exist in the symbol table. This is done as follows:

     my $x = 1; our $y; # declare $y in the symbol table for the current package { local *y = \$x; # make $y an alias of $x in the current scope $y++; } print $x; # prints 2 

    But, as always, be aware of which dynamic region / locale actually performs before use.

  • The lexical scalar can be used as an alias within the for loop:

     my $x = 1; for my $y ($x) { $y++; } print $x; # prints 2 

    this type of lexical alias can even be removed from the loop in closure if necessary

  • You can create array aliases using Perl alias magic for argument lists of routines:

     my $x = 1; my $alias = sub{\@_}->($x); # return a reference to its argument list, # which maintains its aliases $$alias[0]++; print $x; # prints 2 

    but it does not give you more functionality than links, just with a different syntax.

  • And an example of using Perl links:

     my $x = 1; my $y = \$x; # take a reference to $x $$y++; # dereference $y print $x; # prints 2 
+4
source

I found another potential option: Scalar::Alias , which seems to work in Perl 5.12. Obviously, it only pseudonizes scalars, but instead of the equal sign, a bold comma is not required.

0
source

Source: https://habr.com/ru/post/1308821/


All Articles