Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

accessing total number of entries from a field

accessing total number of entries from a field

accessing total number of entries from a field

I have a inventory that has, several fields with identical names, the value is always 1. When someone checks three fields with the same name, output is
Pencils: 1, 1, 1
I want to have the total number inserted, in this case 3 so
Pencils: 3
I realize this is creating an array but I can't seem to access the number. I've tried
if ($Form{$field} =~ /\d/){
                @var = ({$field});
                $var = @var;
                print MAIL "$field: $var\n";
                print MAIL "$field: $Form{$field}\n";
but it never adds it up. All the variables are decoded
at the beginning
foreach $pair (@pairs) {
    local($name, $value) = split(/=/, $pair);
        $name =~ tr/+/ /;
        $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
 $value =~ tr/+/ /;
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
Is this why it won't create an array?

RE: accessing total number of entries from a field

So, you're passing an input field into the CGI with at a name = 'Pencil' and a value = '1,1,1'.
And you want to know how many pencils there are....????
I believe you are lacking one small step....you need to split the string, '1,1,1', into elements when you stick them into your array, @var.
$field = 'Pencil';
$FORM{$field} = '1,1,1'; # simulate input from web form
print "$FORM{$field}\n";
# split usually looks like split(//,$var);, but the comma is a metachar
# so it must be escaped with '\'. So,.....

@vars = split(/\,/,$FORM{$field});
$howMany = $#vars + 1;# add one because array is counted from zero.
print "$howMany\n";

You could do this with a pattern match also, but, I have tried to maintain some consistency with your approach.
'hope this helps....

keep the rudder amid ship and beware the odd typo

RE: accessing total number of entries from a field

Great, that is exactly what was needed. I used pattern matching
if ($Form{$field} =~ /1\,/){
and it all adds up
Thanks so much!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close