TeaK has asked for the wisdom of the Perl Monks concerning the following question:

Hello I'm very new here and I have a question. I have a barcode generator that takes many inputs from a form and generates as many barcodes for inputs filled in . This is nice but you have to enter in each one (time consuming) when more than 10 are needed. Is there a way to just enter a column of numbers, say from a spread sheet into a textarea and have the perl code break each entry per line. Similar to reading lines in from a file. Or can the textarea data be >into a new file , which can then be printed. One number /line as it would be entered in the textarea. Since I am new here , I'm not sure if I will get an email when a response comes in for this question.... Thank you in advance....

Replies are listed 'Best First'.
Re: textarea entries
by jZed (Prior) on Feb 23, 2005 at 01:58 UTC
    Last things first: no there is no email notification, but you can go to your user settings (from your homepage here) and set things so that you get a private message in your inbox here when someone replies.

    And yes, you can do any of the things you mentioned. Probably the simplest is to just use space separate - users can enter as many numbers as they want, separated by one or more blank spaces or newlines. Then in your perl script, you can just use /\s+/ to gather the input.

      Thank you for your replies... I admit it I am a CGI rookie here.... I need a snipet or 2 to see what you are saying. If I show you what I have for the current code to accept the <input type text> entries. Could you suggest the best method to read a textarea instead of multiple text fields. Feel free to alter this code . Thank you in advance
      #!/usr/bin/perl if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } &process; } #The following displays barcode sub process { ($name = $FORM{name});
      more html & print script would be below here Once again I thank you gc
        GAH! Stop right now. Go get CGI and use it. I really mean it, you really should not be using code like what you are doing. Nothing we say about your particular issue will be as important as using the CGI.pm module. Do that first, then come back and ask again.

        update to give an example

        #!perl -w use strict; use CGI qw(:all); my $FORM = param->Vars; my $textarea = $FORM{"text_area_field_name"}; my @numbers = split /\s+/, $textarea.
        (When I said "go get CGI.pm" I was speaking metaphorically, you don't actually need to "get" anything, it comes with perl.
Re: textarea entries
by graff (Chancellor) on Feb 23, 2005 at 06:57 UTC
    Are you talking about a web interface here? Just make a single, large-enough text box that people can type/paste into (like the ones here for posting nodes and replies), and break up the submitted text on whitespace.

    If the values need to be "keyed" in some way (e.g. they need to be submitted in a particular order, or each value needs a label to identify what it's for), and/or if any single value can contain a space, then you'll need to work out a convention that will keep the input properly organized and still be easy for users to grasp and adhere to.

    If you don't get what you're after, post some code -- that makes it easier and more fun for us.

      Thank you for your replies... I want a simple textarea where the users can paste in many serial numbers (either in a column or row with a space/s sepating them). They click submit and the CGI takes each entry as a separate entity instead of one long one. I admit it I am a CGI rookie here.... I need a snipet or 2 to see what you are saying. If I show you what I have for the current code to accept the <input type text> entries. Could you suggest the best method to read a textarea instead of multiple text fields. Feel free to alter this code . Thank you in advance
      #!/usr/bin/perl if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } &process; } #The following displays barcode sub process { ($name = $FORM{name});
      more html & print script would be below here Once again I thank you gc