my @animals = ("frog", "toad", "snake", "grasshopper", "bird");
I've been playing a little with arrays, as you can tell..but doesn't that look weird to anyone else? You can either sort without spaces or you can print "@array" and lose the sort. The only exception I found was when you store the sorted array in a different array and print that instead.my @sorted_animals = (sort @animals); print "@sorted_animals"; # prints with spaces AND is sorted print sort "@animals"; # prints with spaces but doesn't sort print sort @animals; # sorts but doesn't have spaces print sort(@animals); # sorts but doesn't have spaces print sort("@animals"); # prints with spaces but doesn't sort print (sort("@animals")); # prints with spaces but doesn't print (sort(@animals)); # sorts but doesn't have spaces
Is there a way to print a sorted array with spaces without making a new array?
In reply to array sorting by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |