in reply to intermix list of items

That eq definitely does not make sense. I can guess what was in your mind, you probably thought that by using 'eq', sort will group elements for you base on how common they are. No, that is not what sort does. You have to tell sort "between each pair of two elements, how they shall be ordered".

You are looking for something like:

use Data::Dumper; my @list = ('10.1.1.1', '10.1.1.2', '10.2.2.1', '10.2.2.2'); @list = sort intermix @list; print Dumper(@list); sub intermix { return ( substr( $a, 0, rindex($a, '.')) gt substr( $b, 0, rindex($b, '.')) ) ? 1 : 0; }

Replies are listed 'Best First'.
Re^2: intermix list of items
by tstock (Curate) on Oct 10, 2004 at 17:20 UTC
    'gt' refers to the size of the string, running your example solution didn't seem to help. I was going for (and failed) non-equality of the substring means they are identical in sort order by using 'eq'.
      "'gt' refers to the size of the string"

      No. In your code, gt looks at "dictionary sequence".

      If string size/length is what you wanted, say length($str) expliciltly.

      use Data::Dumper; my @foo = ("abc", "bc"); print Dumper(sort bar1 @foo); print Dumper(sort bar2 @foo); sub bar1 { return $a gt $b; } sub bar2 { return length($a) gt length($b); }