Hello!
I have a small script that decodes a cuecat scan of a barcode. A barcode is swiped with the cuecat and the scripts returns the id number of the product.
What I am trying to do is write a script that will process the swipe from a webpage... for example:
a page is displayed with a textfield for the cuecat input (the swipe) then a submit button that will decode the input.
My efforts are posted below -
Thank you very much in advance for any and all assistance!
Jim
----Begin Code----
#!/usr/bin/perl
use CGI;
use CGI qw
standard);
use CGI::Carp qw (fatalsToBrowser confess);
print header,
start_html('the CueCat page'),
start_form,
"Swipe Barcode: ",
textfield('text'),
p,
submit, reset,
end_form,
hr;
if (param()) {
# this begins the actual cuecat translation section
my @outputs;
my %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);
my %types = (cGf2 => 'ISBN', cGen => 'ISBN', fHmg => 'UPC', fGzX => 'UPC-E1');
while(@outputs) {
next if ($_ eq "\n"
;
unless (/^\.(.*)\.(....)\.(.*)\.$/) {
print "invalid code\n";
} else {
my $type = $2;
my $code = $3;
my $output = "";
while ($code =~ /^(..)(.?)(.?)(.*)/) {
$output .= $translation{$1} . $translation{$2} . $translation{$3};
$code = $4;
}
push (@outputs, (($types{$type}) ? "$types{$type} " : '') . "$output\n"
;
}
}
return (@outputs);
# this ends the actual cuecat translation section
print "Product ID is: ", @, hr;
}
print end_html;
----End Code-----
I have a small script that decodes a cuecat scan of a barcode. A barcode is swiped with the cuecat and the scripts returns the id number of the product.
What I am trying to do is write a script that will process the swipe from a webpage... for example:
a page is displayed with a textfield for the cuecat input (the swipe) then a submit button that will decode the input.
My efforts are posted below -
Thank you very much in advance for any and all assistance!
Jim
----Begin Code----
#!/usr/bin/perl
use CGI;
use CGI qw
use CGI::Carp qw (fatalsToBrowser confess);
print header,
start_html('the CueCat page'),
start_form,
"Swipe Barcode: ",
textfield('text'),
p,
submit, reset,
end_form,
hr;
if (param()) {
# this begins the actual cuecat translation section
my @outputs;
my %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);
my %types = (cGf2 => 'ISBN', cGen => 'ISBN', fHmg => 'UPC', fGzX => 'UPC-E1');
while(@outputs) {
next if ($_ eq "\n"
unless (/^\.(.*)\.(....)\.(.*)\.$/) {
print "invalid code\n";
} else {
my $type = $2;
my $code = $3;
my $output = "";
while ($code =~ /^(..)(.?)(.?)(.*)/) {
$output .= $translation{$1} . $translation{$2} . $translation{$3};
$code = $4;
}
push (@outputs, (($types{$type}) ? "$types{$type} " : '') . "$output\n"
}
}
return (@outputs);
# this ends the actual cuecat translation section
print "Product ID is: ", @, hr;
}
print end_html;
----End Code-----