in reply to array sorting

You could do what the others are doing, but I personally don't understand either. I ran all your examples and now I'm wondering why when you treat a scalar as a list, it doesn't get sorted..but as a string, it does. Then the other people are joining on the scalar as if it were a string, I'm not sure I understand that either.

How I do it is a little different:

for (sort @animals) { print "$_ "; }
UPDATE: Well what do you know, without realizing it I didn't interpolete(sp) @animals either.. But I still understand this better than joining a a blank line on a string (how does it know where the spaces are to be printed?)


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Replies are listed 'Best First'.
Re: Re: array sorting
by davido (Cardinal) on Jan 29, 2004 at 07:46 UTC
    Take a deep breath and look at it again.

    @sorted = sort @unsorted; $string = join " ", @sorted; print $string;

    That's the same as....

    print join( " ", sort @unsorted );

    Except that you're not using two intermediate variables. sort takes a list or array as input, and spits out a sorted list which you can either slurp into an array, or send into the input side of join. join takes a list or array as input, and joins its elements together with whatever you put between the quotes, to create a single big-old string. print takes a list (even if the list is one element... and in this case the one element is the string which is the output of join).

    Hope this helps...


    Dave