#!/usr/bin/env perl -l use strict; use warnings; print '*** Create @x with no elements ***'; my @x; print 'Elements in @x: ', scalar @x; print '*** Use array index beyond end as RHS of assignment ***'; my $y = $x[42]; print 'Value assigned from beyond end of @x: ', defined $y ? $y : ''; print 'Elements in @x: ', scalar @x; print '*** Use array index beyond end as LHS of assignment ***'; $x[21] = 'hello'; for my $i (0, 10, 21, 32) { print "Index: $i"; print 'Value: ', defined $x[$i] ? $x[$i] : ''; } print 'Elements in @x: ', scalar @x; #### *** Create @x with no elements *** Elements in @x: 0 *** Use array index beyond end as RHS of assignment *** Value assigned from beyond end of @x: Elements in @x: 0 *** Use array index beyond end as LHS of assignment *** Index: 0 Value: Index: 10 Value: Index: 21 Value: hello Index: 32 Value: Elements in @x: 22 #### @hash{'goodbye', 'world'} = (); #### #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my %hash = ('hello', 1, 'goodbye', 2, 'world', 3, 'mars', 4); print Dumper \%hash; $hash{goodbye} = ()[0]; $hash{world} = ()[1]; print Dumper \%hash; #### $VAR1 = { 'hello' => 1, 'goodbye' => 2, 'world' => 3, 'mars' => 4 }; $VAR1 = { 'hello' => 1, 'goodbye' => undef, 'world' => undef, 'mars' => 4 }; #### #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my %hash = ('hello', 1, 'goodbye', 2, 'world', 3, 'mars', 4); print Dumper \%hash; @hash{'goodbye', 'world'} = ('farewell'); print Dumper \%hash; #### $VAR1 = { 'hello' => 1, 'goodbye' => 2, 'world' => 3, 'mars' => 4 }; $VAR1 = { 'hello' => 1, 'goodbye' => 'farewell', 'world' => undef, 'mars' => 4 };