#!/usr/bin/perl -w use strict; use Data::Dumper; use diagnostics -verbose; use constant PART => 0; use constant REV => 1; #This is where the user will enter the Part Number and Revision Level print "Enter the Part Number you wish to search for: "; my $part = ; chomp $part; while (!$part){ # while $PartNumber is empty keep asking print "PartNumber? "; $part = ; chomp($part); } print "Enter the Revision for ($part): "; my $rev = ; chomp $rev; while (!$rev){ # while $rev is empty keep asking print "Revision? "; $rev = ; chomp($rev); } my $searchresult = search( part => $part, rev => $rev, filename => './file.db', ); print ref $searchresult ? "Located Part Number: @{[join ':', @$searchresult ]}\n" # print the part number and the records : "Your Part Number ($part) Rev ($rev) could not be found....\n"; #print if part number or rev is invalid # subroutine that takes the arguments from my $searchresult and checks # the text file for a matching part number and revision level sub search { my %args = @_; my $retval; local *PARTS_DB; open PARTS_DB, $args{filename} or die "Cannot open file $args{filename}: $!"; while (my $record = ) { chomp $record; my @record = split /\|/, $record; next unless $record[PART] eq $args{part} and $record[REV] eq $args{rev}; close PARTS_DB or die "Can't close PARTS_DB $args{filename}: $!"; return \ @record; } }