SPUG: Sort an array question

Asim Jalis asimjalis at acm.org
Thu Dec 26 18:08:12 CST 2002


Brian Hatch wrote:
> Andrew Reid wrote:
> > While attempting to gain more meaninful employment, I
> > happened upon this question from a prospective provider of
> > opportunity.  "Sort an array alphabetically without using the
> > Perl sort command." This was provided by someone not familiar
> > with Perl but other languages and all work was shown on a
> > white board.  I think I did OK, there were a few holes in the
> > code, and I decided to really give it a shot. This works and
> > is very close to what I provided on the spot.
> > 
> > If any of you have some free time and thoughts, I'd
> > appreciate them!  Tell me what you think.
> 
> Though you could certainly code up a bubble/insertion/quick sort
> or such, how 'bout 
> 
> open2(*R, *W, "sort") or die "Can't run sort!":

Is there a way to use map and grep to do a bubble sort (or
insertion sort) in a functional programming way? Something like: 

@sorted_list = map { . . . } [. . . stuff . . . ] @unsorted_list;

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org




More information about the spug-list mailing list