#!/usr/bin/perl

# $index = linear_string( \@array, $target )
#      @array is (unordered) strings
#      on return, $index is undef or else $array[$index] eq $target

sub linear_string {
    my ($array, $target) = @_;

    for ( my $i = @$array; $i--; ) {
        return $i if $array->[$i] eq $target;
    }
    return undef;
}


@array = qw(Whiteboards are so much better than blackboards.  I'm one of those people
who shudders at the thought of fingernails (or even errant chalk) squealing across
blackboards.  But I got no problem at all with whiteboards.);

print linear_string(\@array, "fingernails"), "\n";

$target = "blackboards.";

# Get all the matches.
@matches = grep { $_ eq $target } @array;

print "Matches: @matches\n";

