Lesson 10 of 15
Array & Hash Operations
Working with Arrays and Hashes
Joining Arrays
join creates a string from an array:
my @words = ("hello", "world");
say join(" ", @words); # hello world
say join(", ", @words); # hello, world
Splitting Strings
split creates an array from a string:
my @parts = split(",", "a,b,c");
say $parts[0]; # a
say $parts[1]; # b
Sorting and Reversing
my @nums = (3, 1, 4, 1, 5);
my @sorted = sort @nums;
my @rev = reverse @nums;
Keys and Values
Extract keys or values from a hash:
my %h = (a => 1, b => 2);
my @k = keys %h;
my @v = values %h;
Your Task
Split the string "one,two,three" by comma and print each word on its own line.
JS Transpiler loading...
Loading...
Click "Run" to execute your code.