#!/usr/bin/perl -w 

use strict;

my $string = "There are several words in this string";
my @words = split( / /, $string);

# sort one array into another array.
my @sortedWords = sort(@words);
print "Sorted words: @sortedWords\n";

# try to sort numbers
my @numbers = ("1", "2", "-1", "10", "15", "-11", "67");
my @sortedNumbers = sort(@numbers);
print "Sorted numbers 1: @sortedNumbers\n";

# use a block of code to say how to compare two elements
@sortedNumbers = sort { $a <=> $b } @numbers;
print "Sorted numbers 2: @sortedNumbers\n";

# or use a subroutine 
sub numerically  {
  $a <=> $b;
}

@sortedNumbers = sort numerically @numbers;


