#!/usr/bin/perl -w use strict; my @array1 = ("jerry", "abe", "hope", "crazy_horse", "lewis","bob"); print "initial array order: @array1\n"; my @array = sort @array1; print "The default sort: @array\n"; @array = sort{$a cmp $b}@array1; print "The same sort order: @array\n\n"; @array = sort{ print "comparing $a and $b \n"; $a cmp $b; } @array1; print "\n"; print "The same thing: @array\n\n"; __END__ initial array order: jerry abe hope crazy_horse lewis bob The default sort: abe bob crazy_horse hope jerry lewis The same sort order: abe bob crazy_horse hope jerry lewis comparing jerry and abe comparing hope and crazy_horse comparing lewis and bob comparing abe and crazy_horse comparing crazy_horse and jerry comparing jerry and hope comparing abe and bob comparing bob and crazy_horse comparing crazy_horse and lewis comparing lewis and hope comparing lewis and jerry The same thing: abe bob crazy_horse hope jerry lewis