|
Posted by Tomasz Chmielewski on March 4, 2008, 12:01 pm
Please log in for more thread options Abigail schrieb:
> _
> Tomasz Chmielewski (tch@nospam.syneticon.net) wrote on VCCXCIX September
> @@ Let's say I have an array consisting of:
> @@
> @@ some-name-10
> @@ some-name-9
> @@ some-name-102
> @@ some-name-89
> @@
> @@ I would like to sort it the "human way", with the result:
> @@
> @@ some-name-9
> @@ some-name-10
> @@ some-name-89
> @@ some-name-102
> @@
> @@
> @@ What would be the suggested way to do it?
> @@
> @@ I would use 'split', but "some-name" is not static, and can be
> @@ "some-other-name" or just "name" a task later.
> @@
> @@ For the same reason, using 'substr' won't work.
> @@
> @@ Unless I write a subroutine to it.
> @@
> @@
> @@ What do you guys use to sort such things?
>
>
> Well, that depends. Your specification, or rather lack of specification,
> allows multiple interpretations. If you have:
>
> sort-name-20
> sort-name-7
> name-15
> name-8
>
> do you want:
>
> name-8
> name-15
> sort-name-7
> sort-name-20
>
> or
>
> sort-name-7
> name-8
> name-15
> sort-name-20
The latter. And the "name" would always be the same (it would only
change in the next iteration; but for a given iteration, all names would
be the same).
So essentially, as I wrote:
some-name-10
some-name-9
some-name-102
some-name-89
with the result:
some-name-9
some-name-10
some-name-89
some-name-102
But I think "sub extract" discussed earlier is simple enough for this
case, and I used it.
--
Tomasz Chmielewski
http://wpkg.org
|