Skip to content

Instantly share code, notes, and snippets.

@smls
Last active Aug 29, 2015
Embed
What would you like to do?
Variables/containers/objects in Perl vs Perl 6
## 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