perl-DestructAssign-0.002007-alt3.1.i586.rpm


Advertisement

Description

perl-DestructAssign - Destructuring assignment

Property Value
Distribution ALT Linux Sisyphus
Repository Autoimports i586
Package filename perl-DestructAssign-0.002007-alt3.1.i586.rpm
Package name perl-DestructAssign
Package version 0.002007
Package release alt3.1
Package architecture i586
Package type rpm
Category Development/Perl
Homepage -
License -
Maintainer -
Download size 37.69 KB
Installed size 37.69 KB
This mod provides destructuring assignment for Perl.
You can capture (by value) or bind (by alias) variables into
part of a potentially large and complex data structure.
I expect it to bring following benefits:
=over 4
=item enhance the performance by avoiding repeatedly digging into complex data structures
Suppose we have data structures like this:
my $player1 = {
id => 25,
hp => 8100,
armor => {
body => {
id => 21,
name => 'iron suit',
protect => 10,
durability => 100,
},
hand => {
id => 29,
name => 'iron sword',
attack => 15,
durability => 100,
},
},
};
my $player2 = ...;
Instead of
while( $player1->{hp}>0 && $player2->{hp}>0 ) {
my $hit1 =
($player1->{armor}{hand}{durability} && $player1->{armor}{hand}{attack}) -
($player2->{armor}{body}{durability} && $player2->{armor}{body}{protect});
my $hit2 =
($player2->{armor}{hand}{durability} && $player2->{armor}{hand}{attack}) -
($player1->{armor}{body}{durability} && $player1->{armor}{body}{protect});
$hit1 = 1 if( $hit1 <= 0 );
$hit2 = 1 if( $hit2 <= 0 );
$player1->{hp} -= $hit2;
$player2->{hp} -= $hit1;
--$player1->{armor}{hand}{durability} if( $player1->{armor}{hand}{durability} );
--$player1->{armor}{body}{durability} if( $player1->{armor}{body}{durability} );
--$player2->{armor}{hand}{durability} if( $player2->{armor}{hand}{durability} );
--$player2->{armor}{body}{durability} if( $player2->{armor}{body}{durability} );
}
We could write
des_alias [
{
hp => my $hp1,
armor => {
body => {
protect => my $protect1,
durability => my $body_dura1,
},
hand => {
attack => my $attack1,
durability => my $hand_dura1,
},
}
},
{
hp => my $hp2,
armor => {
body => {
protect => my $protect2,
durability => my $body_dura2,
},
hand => {
attack => my $attack2,
durability => my $hand_dura2,
},
}
},
] = [$player1, $player2];
while( hp1>0 && hp2>0 ) {
my $hit1 = ($hand_dura1 && $attack1) - ($body_dura2 && $protect2);
my $hit2 = ($hand_dura2 && $attack2) - ($body_dura1 && $protect1);
$hit1 = 1 if( $hit1 <= 0 );
$hit2 = 1 if( $hit2 <= 0 );
$hp1 -= $hit2;
$hp2 -= $hit1;
--$hand_dura1 if( $hand_dura1 );
--$body_dura1 if( $body_dura1 );
--$hand_dura2 if( $hand_dura2 );
--$body_dura2 if( $body_dura2 );
}
=item enhance the readability by pointing out all the elements you might touch at the begining of each subroutine
It's a good habit to write named parameters instead of access @_ directly
(except you want to modify the caller's arguments).
This mod extend the ability to name parameters in the deep structure.
You can explicitly list all the elements you might touch in the subroutine.
sub f {
des [my $x, { id => my $id, amount => my $amount }] = \@_;
des_alias [my $x, { id => my $id, amount => my $amount }] = \@_;
}
=back
I've tested this mod in Perl 5.8.9, 5.10.1, 5.12.5, 5.14.4, 5.16.3, 5.18.2, 5.20.0 (by perlbrew) on x86_64.

Alternatives

Package Version Architecture Repository
perl-DestructAssign-0.002007-alt3.1.x86_64.rpm 0.002007 x86_64 Autoimports
perl-DestructAssign - - -

Requires

Name Value
/usr/lib/perl5 -
libc.so.6(GLIBC_2.0) -
libc.so.6(GLIBC_2.1.3) -
libc.so.6(GLIBC_2.4) -
libperl-5.28.so -
perl(AutoLoader.pm) -
perl(XSLoader.pm) -
rpmlib(PayloadIsLzma) -
rpmlib(SetVersions) -
rtld(GNU_HASH) -

Provides

Name Value
perl(DestructAssign.pm) = 0.002.007
perl-DestructAssign = 0.002007-alt3.1

Download

Type URL
Mirror ftp.altlinux.org
Binary Package perl-DestructAssign-0.002007-alt3.1.i586.rpm
Source Package perl-DestructAssign-0.002007-alt3.1.src.rpm

Install Howto

  1. Add the following line to /etc/apt/sources.list:
    
    rpm [Sisyphus] http://ftp.altlinux.org/pub/distributions/ALTLinux/autoimports/Sisyphus i586 autoimports
    rpm [Sisyphus] http://ftp.altlinux.org/pub/distributions/ALTLinux/autoimports/Sisyphus noarch autoimports
    
  2. Update the package index:
    # sudo apt-get update
  3. Install perl-DestructAssign rpm package:
    # sudo apt-get install perl-DestructAssign

Files

Path
/usr/lib/perl5/DestructAssign.pm
/usr/lib/perl5/auto/DestructAssign/DestructAssign.so
/usr/lib/perl5/auto/DestructAssign/autosplit.ix
/usr/share/doc/perl-DestructAssign-0.002007/Changes
/usr/share/doc/perl-DestructAssign-0.002007/README

See Also

Package Description
perl-Devel-Assert-1.06-alt3.1.i586.rpm assertions for Perl >= 5.14
perl-Devel-CCompat-C99-ScopedVariables-0.002-alt3.1.i586.rpm tests support for C99 scoped variables
perl-Devel-CCompat-C99-VariableLengthArrays-0.002-alt3.1.i586.rpm tests support for C99 variable length arrays
perl-Devel-Callsite-1.0.1-alt1.1.i586.rpm Get caller return OP address and Perl interpreter context
perl-Devel-ChangePackage-0.08-alt4.1.i586.rpm Change the package code is currently being compiled in
perl-Devel-ContinuousProfiler-0.12-alt4.1.i586.rpm Ultra cheap profiling for use in production environments
perl-Devel-CountOps-0.01-alt4.1.i586.rpm Simply and precisely count operations in Perl code
perl-Devel-FastProf-0.08-alt8_30.i586.rpm Fast perl per-line profiler
perl-Devel-FindBlessedRefs-1.253-alt4.1.i586.rpm perl module Devel-FindBlessedRefs
perl-Devel-GDB-Breakpoint-0.02-alt4.1.i586.rpm Create easily identifiable gdb breakpoints in Perl code
perl-Devel-Gladiator-0.07-alt4.1.i586.rpm Walk Perl's arena
perl-Devel-GlobalDestruction-XS-0.03-alt5_9.i586.rpm Faster implementation of the Devel::GlobalDestruction API
perl-Devel-GoFaster-0.001-alt2.1.i586.rpm optimise executable Perl ops
perl-Devel-Hexdump-0.02-alt4.1.i586.rpm Print nice hex dump of binary data
perl-Devel-Hook-0.011-alt2.1.i586.rpm Mess around with BEGIN/CHECK/INIT/END blocks
Advertisement
Advertisement