vendion has asked for the wisdom of the Perl Monks concerning the following question:
I have a problem with using an array inside a format when I try I get unitialized value error but I can use that same array in a print statement and it works just fine.
This is the output that I get#!/usr/bin/perl use strict; use warnings; use DBI; #Declaire all variables now! my @customer_comp; #Structure for @customer_comp array is as follows: #comp. id, Cust. id, comp. man, comp. model, mod num, OS, error msg, s +ervic, probdesc, didDiagnostic, login pw my @customer; #Structure for @customer array is as follows: #id, first name, last name, email, phone, date my $sth; my @ref_Customer; my @ref_Computer; my $database = "Repairs"; #Specify the database to be used my $hostname = "192.168.1.111"; #Connect to the MySQL server my $port = '3306'; #MySQL port my $user = 'username'; #MySQL username my $password = 'password'; #MySQL password my $dsn; my $dbh; my $version = '1.1.9'; #Script version number main(); #break here sub main() { if ( $^O =~ /MSWin32/ ) { system('cls'); } else { system('clear'); } print "Cleveland State CC Computer Repairs\n\n"; print "Version $version\n", "Copyleft 2009 Adam Jimerson & Andy Arp\n"; print "----------------------------\n", "Main Menu, To make a selection specify the number for that ac +tion\n"; print "1. Add New Computer to Database\n"; print "2. Edit Computer Status in Database\n"; print "3. Remove a Computer from Database\n"; print "4. Look up Computer Information\n"; print "5. List All Repair Requests\n"; print "6. Print Final Report For Customer\n"; #this should be don +e to ensure we provide information on a repair #to the customer on paper print "7. Check Computer Status\n"; print "8. Quit the program\n"; print "Action: "; my $option = <STDIN>; chomp($option); if ( $option == 1 ) { print_form(); } elsif ( $option == 2 ) { print_edit(); } elsif ( $option == 3 ) { print_remove(); } elsif ( $option == 4 ) { print_lookup(); } elsif ( $option == 5 ) { print_all(); } elsif ( $option == 6 ) { print_report(); } elsif ( $option == 7 ) { print_checkstatus(); } elsif ( $option == 8 ) { exit 0; } else { print "Error: Option $option invalid\n"; <STDIN>; main(); } } sub print_form { print "system('date')"; print "Today's Date (YYYY-MM-DD): "; #Until a better way is found +to get the date, ask for it $customer[5] = <STDIN>; chomp($customer[5]); print "\nCustomer Information\n", "-----------------------\n"; #Begin the customer information f +orm print "Customer First Name: "; $customer[1] = <STDIN>; chomp($customer[1]); print "Customer Last Name: "; $customer[2] = <STDIN>; chomp($customer[2]); print "Customer Barcode, Structure 10 chars incl hyphen: "; $customer[0] = <STDIN>; chomp($customer[0]); $customer_comp[1] = $customer[0]; print "Customer Phone #: "; $customer[4] = <STDIN>; chomp($customer[4]); print "Customer Email: "; $customer[3] = <STDIN>; chomp($customer[3]); print "\nComputer Information\n", "-----------------------\n"; #Begin the computer information f +orm $customer_comp[0] = ''; print "Computer Manufacturer: "; $customer_comp[2] = <STDIN>; chomp($customer_comp[2]); print "Computer Model: "; $customer_comp[3] = <STDIN>; chomp($customer_comp[3]); print "Computer Model #: "; $customer_comp[4] = <STDIN>; chomp($customer_comp[4]); print "Error Message (if any): "; $customer_comp[6] = <STDIN>; chomp($customer_comp[6]); print "Operating System: "; $customer_comp[5] = <STDIN>; chomp($customer_comp[5]); print "Problem Description: "; $customer_comp[8] = <STDIN>; chomp($customer_comp[8]); print "Administrator/Root Login Password: "; $customer_comp[10] = <STDIN>; chomp($customer_comp[10]); print "Computer Service Needed: "; $customer_comp[7] = <STDIN>; chomp($customer_comp[7]); $customer_comp[9] = '0'; #$customer[5] = system('date'); db_add(); } sub db_add { #Insert values retreived from print_form() $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; $dbh = DBI->connect($dsn, $user, $password, {RaiseError => 1}); $dbh->do("INSERT INTO computer (compid, custid, compManufacturer, +compModel, compModelNum, OS, errorMsg, serviceNeeded, problemDescript +ion, didDiagnostic, password) VALUES (?,?,?,?,?,?,?,?,?,?,?)", {}, @c +ustomer_comp); $dbh->do("INSERT INTO customers (id, firstname, lastname, email, p +hone, date) VALUES (?,?,?,?,?,?)", {}, @customer); $dbh->disconnect(); main(); } sub print_lookup { print "Please Scan System Barcode: "; #Get barcode information $customer[0] = <STDIN>; chomp($customer[0]); db_fetch(); } sub db_fetch() { $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; $dbh = DBI->connect($dsn, $user, $password, {RaiseError => 1}); $sth = $dbh->prepare("SELECT * FROM customers WHERE id = '$custome +r[0]'"); eval { die "Prepare has failed"; }; $sth->execute(); eval { die "Execute has failed"; }; @ref_Customer = $sth->fetchrow_array(); eval { die "Fetchrow has failed"; }; print "Customer\n"; print "@ref_Customer\n"; $sth->finish; $sth = $dbh->prepare("SELECT * FROM computer WHERE custid = '$cust +omer[0]'"); eval { die "Prepare has failed"; }; $sth->execute(); eval { die "Execute has failed"; }; my @ref_Computer = $sth->fetchrow_array(); eval { die "Fetchrow has failed"; }; print "Computer\n"; print "@ref_Computer\n"; $sth->finish; $dbh->disconnect; <STDIN>; #Pause execution of the script so that the query output c +an be read main(); } sub print_all { $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; $dbh = DBI->connect($dsn, $user, $password, {RaiseError => 1}); $sth = $dbh->prepare("SELECT * FROM customers"); eval { die "Prepare has failed"; }; $sth->execute(); eval { die "Execute has failed"; }; print "Customer\n"; while (@ref_Customer = $sth->fetchrow_array()) { eval { die "Fetchrow has failed"; }; print "@ref_Customer\n"; } $sth->finish; $sth = $dbh->prepare("SELECT * FROM computer"); eval { die "Prepare has failed"; }; $sth->execute(); eval { die "Execute has failed"; }; print "Computer\n"; while (@ref_Computer = $sth->fetchrow_array()) { eval { die "Fetchrow has failed"; }; print "@ref_Computer\n"; } $sth->finish; $dbh->disconnect; <STDIN>; #Pause execution so output can be read main(); } sub print_remove { print "Please Scan System Barcode: "; #Get Barcode information $customer[0] = <STDIN>; chomp($customer[0]); db_remove(); } sub db_remove { $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; $dbh = DBI->connect($dsn, $user, $password, {RaiseError => 1}); $dbh->do("DELETE FROM customers WHERE id = '$customer[0]'"); $dbh->do("DELETE FROM computer WHERE custid = '$customer[0]'"); $dbh->disconnect(); main(); } sub print_edit { print "Please Scan Barcode For Entry To Edit:"; $customer[0] = <STDIN>; chomp($customer[0]); print "Is machine complete? (1 = True, 0 = False)"; my $status = <STDIN>; #God damn Andy stop making up new scaliers i +f there is a spot for it in the array chomp($status); if ( $status == 1 ) { db_edit(); } elsif ( $status == 0 ) { print "Error, Do not edit status until machine is complete.\n" +; <STDIN>; main(); } } sub db_edit { $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; $dbh = DBI->connect($dsn, $user, $password, {RaiseError => 1}); $sth = $dbh->prepare("SELECT didDiagnostic FROM computer WHERE cus +tid = '$customer[0]'"); eval { die "Prepare has failed"; }; $sth->execute(); eval { die "Execute has failed"; }; @ref_Computer = $sth->fetchrow_array(); eval { die "Fetchrow has failed"; }; print "Current Status:"; if ( @ref_Computer == "0" ) { print "Not Completed\n"; } elsif ( @ref_Computer == "1" ) { print "Completed\n"; } else { print "Customer Not Found.\n"; } $sth->finish; if ( @ref_Computer == "0" ) { #$dbh->do ("INSERT INTO computer (didDiagnostic) VALUES ("0")"; print "Edit Successful"; <STDIN>; db_check(); } else { print "Either computer has already been completed or is not found. +"; <STDIN>; main(); } } sub print_checkstatus { print "System Barcode: "; $customer[0] = <STDIN>; chomp($customer[0]); db_check(); } sub db_check { $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; $dbh = DBI->connect($dsn, $user, $password, {RaiseError => 1}); $sth = $dbh->prepare("SELECT didDiagnostic FROM computer WHERE cus +tid = '$customer[0]'"); eval { die "Prepare has failed"; }; $sth->execute(); eval { die "Execute has failed"; }; @ref_Computer = $sth->fetchrow_array(); eval { die "Fetchrow has failed"; }; print "Current Status:"; if ( @ref_Computer == "0" ) { print "Not Completed"; <STDIN>; } elsif ( @ref_Computer == "1" ) { print "Completed"; <STDIN>; } $sth->finish; main(); } sub print_report { print "This function designed to be used on front desk ONLY!\n"; print "Please enter barcode number:"; $customer[0] = <STDIN>; chomp($customer[0]); db_report(); } sub db_report { open(OUTFILE, ">>/tmp/repairs") or die $!; $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; $dbh = DBI->connect($dsn, $user, $password, {RaiseError => 1}); $sth = $dbh->prepare("SELECT * FROM customers WHERE id = '$custome +r[0]'"); eval { die "Prepare has failed"; }; $sth->execute(); eval { die "Execute has failed"; }; @ref_Customer = $sth->fetchrow_array(); eval { die "Fetchrow has failed"; }; $sth->finish; $sth = $dbh->prepare("SELECT * FROM computer WHERE custid = '$cust +omer[0]'"); eval { die "Prepare has failed"; }; $sth->execute(); eval { die "Execute has failed"; }; my @ref_Computer = $sth->fetchrow_array(); eval { die "Fetchrow has failed"; }; print "Computer\n"; print "@ref_Computer[2..5]\n"; write; print OUTFILE @ref_Customer, "\n", @ref_Computer[2..5]; $sth->finish; $dbh->disconnect; <STDIN>; close(OUTFILE); # system("lpr -# 1 -o prettyprint -r /tmp/repairs"); #Prints out t +wo copies, formats the page with a banner, and removes /tmp/repairs w +hen done print "Would you like to remove this customer and computer? (y = Y +es, n = No)\n"; my $option = <STDIN>; chomp($option); if ( lc($option) eq "y" ) { db_remove(); } elsif ( lc($option) eq "n" ) { print "Did Not Remove\n"; <STDIN>; main(); } } format STDOUT_TOP= ID First Name Last Name Email Address Phone Number Dat +e Comp. Manufacturer Comp. Model Model Number OS ========== ========== ============ ================ ============ === +======= ================== =========== ============ ============= . format STDOUT= @<<<<<<<<< @<<<<<<<< @<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>>> +>>>> @>>>>>>>>>> @<<<<<<<<<<<<<< @<<<<<<<<<<<<<<< @>>>>>>>>>> @<<<<<< +<<<<<< $ref_Customer[0], $ref_Customer[1], $ref_Customer[2], $ref_Customer[3] +, $ref_Customer[4], $ref_Customer[5], $ref_Computer[2], $ref_Computer +[3], $ref_Computer[4], $ref_Computer[5] .
Anyone know what I am missing to fix this?Computer Dell Dimension 2350 Windows XP Use of uninitialized value in formline at /home/cscc/bin/repairs.pl li +ne 410, <STDIN> line 2. Use of uninitialized value in formline at /home/cscc/bin/repairs.pl li +ne 410, <STDIN> line 2. Use of uninitialized value in formline at /home/cscc/bin/repairs.pl li +ne 410, <STDIN> line 2. Use of uninitialized value in formline at /home/cscc/bin/repairs.pl li +ne 410, <STDIN> line 2. ID First Name Last Name Email Address Phone Number Dat +e Comp. Manufacturer Comp. Model Model Number OS ========== ========== ============ ================ ============ === +======= ================== =========== ============ ============= 000-000001 John Doe xxxxxxx@xxxxxxxx.net (xxx)xxx-xxxx 20 +09-09-15
|
|---|