#! /usr/bin/perl use strict ; use warnings ; $|++ ; # First, read the data file into an array. open SCHOOLS, 'schools.dat' or die "Cannot open file: $!" ; chomp( my @rows = ) ; # Next, rip each row into an array ref of fields, making a 2d array. my @table = map { [ split /\|/ ] } @rows ; # Last, test out the function. print "ID 4 matches " . get_schoolname( 4 ) . "\n" ; print "ID 3 matches " . get_schoolname( 3 ) . "\n" ; print "ID 2 matches " . get_schoolname( 2 ) . "\n" ; print "ID 1 matches " . get_schoolname( 1 ) . "\n" ; sub get_schoolname { my $id = shift ; for ( @table ) { return $_->[1] if $id == $_->[0] ; } } exit ;