
yim11
Novice
Dec 19, 2000, 7:44 AM
Post #1 of 3
(581 views)
|
input help needed
|
Can't Post
|
|
Hello! I have the following script, that almost works as it should, but I have to change the input for a section of the script, and don't know how. I have posted the code below and commented the section that I am having troubles with. Thanks in advance for any and all help! Jim ---Begin Code--- #!/usr/bin/perl # CGI routines use CGI_Lite; my $cgi = new CGI_Lite; my %in = $cgi->parse_form_data; # get barcode scan from input my $scan = $in{"SCAN"}; if ($scan) { my $translation = translate($scan); print "Content-type: text/html\n\n"; print "Product ID is: $translation"; } else {prompt();} sub translate { my ($scan) = @_; # do your translation code here with $scan as the input #this is the section I need help with 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(<>) { 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); } sub prompt { print "Content-type: text/html\n\n"; print qq~ <html><body> <form method="post" action="cat2.pl"> <input type="text" name="SCAN"> <input type="submit"> </form> </body></html> ~; } ---End Code---
|