Le Blanc wrote:
>
> Greetings,
Hello,
> Here is my question. In the below code I have the user enter in a
> part number and revision. These are then written into a text file.
> All this works as it should. The next step that I want to get to is
> this. When the user enters the part number and revision I would like
> the script to first look at the text file and see if the number already
> exists. If it does, I then want any information that follows that number
> to be outputted to the screen. If the number does not exist then I want
> the script to write it to the text file. I hope this is clear. When it
> outtputs to the screen I need a way to tell it what part of the text
> file to actually print. I do not want the whole file to print.
> So in a nutshell, how can I have it look at the text file for the part
> number and then print out the information.
If your part numbers are unique then you should probably be using a hash
tied to a DB file. If the text file is static then you should create an
index to look up the sections you want to display.
> I know that the code does not look pretty, but I am learning. I will
> eventually learn to format it more properly. Thank you for your help.
>
>
> print "What is the Part Number that you would like to look up?\n";
> my $PartNumber = <STDIN>;
> chomp($PartNumber);
> while (!$PartNumber){ ## while $PartNumber is empty keep asking
> print "PartNumber? ";
> $PartNumber = <STDIN>;
> chomp($PartNumber);
> }
No reason to duplicate all that code:
print "What is the Part Number that you would like to look up?\n";
my $PartNumber;
do {
print "PartNumber? ";
chomp( $PartNumber = <STDIN> );
} until $PartNumber; ## while $PartNumber is empty keep asking
> print "What is the Revision level for $PartNumber?\n";
> my $Revision = <STDIN>;
> chomp($Revision);
> while (!$Revision){ ## while $Revision is empty keep asking
> print "Revision? ";
> $Revision = <STDIN>;
> chomp($Revision);
> }
print "What is the Revision level for $PartNumber?\n";
my $Revision;
do {
print "Revision? ";
chomp( $Revision = <STDIN> );
} until $Revision; ## while $Revision is empty keep asking
> open(FILE, '>>fai.txt') || die $!;
> printf FILE "\t$PartNumber Rev. $Revision\t";
> close(FILE);
use DB_File;
tie my %hash, 'DB_File', 'db_filename';
$hash{ $PartNumber } = $Revision;
untie %hash;
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]