Last active
August 29, 2015 13:55
-
-
Save smls/8693027 to your computer and use it in GitHub Desktop.
Variables/containers/objects in Perl vs Perl 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Storing three integers in a variable in Perl 5 ## | |
my $a = [2, 4, 6]; # a scalar variable aliased to a reference to an ARRAY object containing three SCALAR objects | |
my @a = (2, 4, 6); # an array variable aliased to an ARRAY object containing three SCALAR objects | |
## Storing three integers in a variable in Perl 6 ## | |
my $a = (2, 4, 6); # an item variable bound to a Scalar object containing one Parcel object containing three Int objects | |
my $a = list 2, 4, 6; # an item variable bound to a Scalar object containing one List object containing three Int objects | |
my $a = [2, 4, 6]; # an item variable bound to a Scalar object containing one Array object containing three Int objects | |
my $a = Array.new(2, 4, 6); # ditto | |
my $a := 2, 4, 6; # an item variable bound to a Parcel object containing three Int objects | |
my $a := (2, 4, 6); # ditto | |
my $a := list 2, 4, 6; # an item variable bound to a List object containing three Int objects | |
my $a := [2, 4, 6]; # ??? | |
my $a := Array.new(2, 4, 6); # an item variable bound to an Array object containing three Int objects | |
my @a = 2, 4, 6; # an array variable bound to an Array object containing three Int objects | |
my @a = (2, 4, 6); # ditto | |
my @a = list 2, 4, 6; # ditto | |
my @a = Array.new(2, 4, 6); # ditto | |
my @a := 2, 4, 6; # an array variable bound to a Parcel object containing three Int objects | |
my @a := (2, 4, 6); # ditto | |
my @a := list 2, 4, 6; # an array variable bound to a List object containing three Int objects | |
my @a := Array.new(2, 4, 6); # an array variable bound to an Array object containing three Int objects | |
# Also, in some of those cases the Array/List object will have the ":flattens" attribute set, and in others not (though I don't understand what governs that). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment