Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: array sorting
by Caron (Friar) on Jan 29, 2004 at 07:05 UTC | |
|
Re: array sorting
by davido (Cardinal) on Jan 29, 2004 at 07:37 UTC | |
|
Re: array sorting
by davido (Cardinal) on Jan 29, 2004 at 07:02 UTC | |
by Abigail-II (Bishop) on Jan 29, 2004 at 10:17 UTC | |
by davido (Cardinal) on Jan 29, 2004 at 17:41 UTC | |
|
Re: array sorting
by sulfericacid (Deacon) on Jan 29, 2004 at 07:28 UTC | |
by davido (Cardinal) on Jan 29, 2004 at 07:46 UTC | |
|
Re: array sorting
by Roger (Parson) on Jan 29, 2004 at 07:01 UTC | |
by Anonymous Monk on Jan 29, 2004 at 09:58 UTC | |
by Roger (Parson) on Jan 29, 2004 at 22:38 UTC |