
yim11
Novice
Dec 12, 2000, 7:31 AM
Post #1 of 3
(1006 views)
|
combining 2 scripts
|
Can't Post
|
|
Hello, I have 2 scripts - catscan.pl (posted below) and receiving.pl (not posted). Catscan.pl when run waits for a scan from a cuecat barcode scanner and converts the scanned barcode to a id number. Receiving.pl takes users input (id number) and inserts that number into a database. What I would like to have is one script that would allow a user to scan a barcode and the script would convert that scan into a id and insert it into the database. I'm not even sure if this can be done, but if so, I would be grateful to any pointers to resources to help! TIA!! Jim catscan.pl ----------Begin Code---------------- #!/usr/bin/perl5 # divide the UPC into 4 groups of three digits # use the scheme below to translate each digit into its output # # 1 2 3 # # 0 C3 n Z # 1 CN j Y # 2 Cx f X # 3 Ch b W # 4 D3 D 3 # 5 DN z 2 # 6 Dx v 1 # 7 Dh r 0 # 8 E3 T 7 # 9 EN P 6 %translation = ('C3', 0, 'n', 0, 'Z', 0, 'CN', 1, 'j', 1, 'Y', 1, 'Cx', 2, 'f', 2, 'X', 2, 'Ch', 3, 'b', 3, 'W', 3, 'D3', 4, 'D', 4, '3', 4, 'DN', 5, 'z', 5, '2', 5, 'Dx', 6, 'v', 6, '1', 6, 'Dh', 7, 'r', 7, '0', 7, 'E3', 8, 'T', 8, '7', 8, 'EN', 9, 'P', 9, '6', 9); %types = ('cGf2', 'ISBN', 'cGen', 'ISBN', 'fHmg', 'UPC', 'fGzX', 'UPC-E1'); while(<>) { exit if $_ eq "\n"; if (!/^\.(.*)\.(....)\.(.*)\.$/) { print "invalid code\n"; exit; } $id = $1; $type = $2; $code = $3; $output = ""; while ($code =~ /^(..)(.?)(.?)(.*)/) { $output = $output . $translation{$1}; $output = $output . $translation{$2}; $output = $output . $translation{$3}; $code = $4; } if ($types{$type} ne "") { print "$types{$type} "; } print "$output\n"; } ----------End Code------------
|