#!/usr/bin/perl use strict; use warnings; use Barcode::Cuecat; use DBI; my $db = "database"; my $db_engine = "mysql"; my $host = "localhost"; my $user = "username"; my $password = "password"; my $dbh = DBI->connect("DBI:$db_engine:$db:$host",$user, $password,{ P +rintError => 0}) || die $DBI::errstr; my $bc = new Barcode::Cuecat(); print "Mr. Muskrat's Item Database Lookup\n"; print "Version 1.0\n\n"; ShowWhatToDo(); while (<>) { last if /^\n$/; my $test = $bc->scan($_); my $type = $bc->type(); my $upc = $bc->code(); ShowItemInfo($dbh, $upc); } continue { ShowWhatToDo(); } my $rc = $dbh->disconnect; exit; sub ShowItemInfo { my ($dbh, $upc) = @_; my $table = "upca"; my $select = "upc, units, description"; my $sth; my $where = "upc = $upc"; print "\n"; $sth = $dbh->prepare("SELECT $select FROM $table WHERE $where;"); if (!$sth) { die "Error:" . $dbh->errstr . "\n"; } if (!$sth->execute) { die "Error:" . $sth->errstr . "\n"; } my $row_ref; while($row_ref = $sth->fetchrow_arrayref) { print "UPC: $row_ref->[0]\n"; print "Units: $row_ref->[1]\n"; print "Description: $row_ref->[2]\n"; print "\n"; } my $rv = $sth->finish; } sub ShowWhatToDo { print "----------------------------------------------\n"; print "\n"; print "To get info on an item, scan it's UPC barcode.\n"; print "To exit, press the Enter key.\n\n"; }
In reply to UPC Lookup by Mr. Muskrat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |