Skip to content

Instantly share code, notes, and snippets.

@smls
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smls/8693027 to your computer and use it in GitHub Desktop.
Save smls/8693027 to your computer and use it in GitHub Desktop.
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