[comp.lang.perl] I need help with sort

msw@polyslo.Sun.COM (Michael Walker) (08/17/90)

I have been trying to get the sort() routine to work
for a subset of a string and have not had much
luck.

In the following program I would like the list 
sorted on the last name of the field, the lines
are delimited by ':'.

What am I doing wrong here?


polyslo 67:cat t
#!/files/bin/perl


@list = ("jim:wilson","bob:smith","steve:blanding",
	"carol:walker","mary:stevens");


@sorted = sort inorder @list;

for( $i = 0;
     $i < 5;
     $i = $i + 1)
{
   print("$i: @sorted[$i]\n");
}




sub by_last_name
{
   local($la,$lb,$burn);

   ($burn,$la) = split(/:/,$a);
   ($burn,$lb) = split(/:/,$b);

   if ($la lt $lb)
   {
      return -1;
   }
   elsif ($la gt $lb)
   {
      return 1;
   }

   return 0;
}
polyslo 68:t
0: bob:smith
1: carol:walker
2: jim:wilson
3: mary:stevens
4: steve:blanding
polyslo 69:




ps.  I am running perl3.0.1.5 Patch Level 18 on a Sun4/330 with
SunOS 4.1.


Thanx,

Mike Walker


                //-n-\\                        
        _____---=======---_____                 - msw@Corp.Sun.Com- 
    ====____\   /.. ..\   /____====             (415) 336-5264
  //         ---\__O__/---         \\   Enterprise... Surrender or we'll
  \_\                             /_/   send back your *&^$% tribbles !!

msw@polyslo.Sun.COM (Michael Walker) (08/17/90)

Please ignore my previos posting - it was a bone head error-:)


Live & Learn,

_Mike_