Hello all.  I am using the following subroutine and it is exhibitng an 
undesirable behavior that I can't figure out how to change.

The array @names consists of elements that alternate between domain_# and 
product_# with # representing some positive integral value.  Also, two 
subsequent entries will have the same integral value tacked on after the 
underscore (i.e. domain_12, product_12, domain_3, product_3, etc..)
The if statement that is generating elements of the array @script_info is 
behaving oddly (at least I find its behavior to be odd).

It will successfully add id and product to the anonymous hash being 
composed for each element of @script_info, but does not add domain.  The 
value of $1 alternatives between domain and product.  I thought maybe it 
was a scoping issue, but then why would product be added and not domain?  I 
noticed that reversing the order of product and domain in the @names array 
will cause domain to be added to the hash but not product.  Why then is 
only the first of a pair of values with the same integral value being added 
to the hash?

I hope this explanation is clear.  Thanks in advance for any help!!

sub updateAllScripts {
    my @script_info;
    my @names = $q->param;
    foreach (@names) {
       if (/^(.+)_(\d+)$/) {
          $script_info[$2] = { 'id' => $2, };
          $script_info[$2]->{$1} = $q->param("$_");
       }
    }
    foreach (@script_info) {
       my $query ="update NYT_CODE_AUDIT set DOMAIN = $_->{domain}, PRODUCT 
= $_->{product} where SCRIPT_ID = $_->{id}";
       $cnxdb->execute_async("$query");
    }
    print "<html><head><title>Organizing Code Audit Info</title></head>";
    print qq!<body bgcolor="#ffffff" 
onLoad="window.location='code_audit.cgi'"></body></html>!;

}

Peter Cline
Inet Developer
New York Times Digital 

Reply via email to