Problem with code: when assigning a value to a associative array ex.
$TT{1100}[1][1]= "gg";
the next associative array with $TT{'1101'}[1][1] also gets
the value please explained & help? <br
I understand that with associative array that when you access the values on the array only the values that are associated with a particular key are changed, but may problem is some how may code is assigning values to different key's. i dont know if its on perl or code error?

Has been tested using ActivePerl 5.6.1 &
on unix: Apachi perl -v version 5.005_03 built for i386-freebsd
#!/usr/bin/perl print "Content-type: text/html\n\n"; #Program # Values From Web Page using Post to Simulate Values $INPUT{'quizes'}=2; $INPUT{'assign'}=2; $INPUT{'recit'}=2; $INPUT{'ndays'}=1; $INPUT{'AT32000011'}=1; $INPUT{'QZ132000011'}=1; $INPUT{'RI132000011'}=1; $INPUT{'AS132000011'}=1; $INPUT{'QZ232000011'}=2; $INPUT{'RI232000011'}=2; $INPUT{'AS232000011'}=2; $INPUT{'AT32000012'}=1; $INPUT{'QZ132000012'}=12; $INPUT{'RI132000012'}=12; $INPUT{'AS132000012'}=12; $INPUT{'QZ232000012'}=22; $INPUT{'RI232000012'}=22; $INPUT{'AS232000012'}=22; #Values From File to Simulate with out the files $STUDQT{'32000011'}[0] = 'fname'; $STUDQT{'32000011'}[1] = 'mname'; $STUDQT{'32000011'}[2] = 'lname'; $STUDQT{'32000011'}[3] = 'Sex'; $STUDQT{'32000011'}[1]['01'] = '0'; $STUDQT{'32000011'}[1]['02'] = '0'; + + ; $STUDQT{'32000011'}[1]['03'] = '0'; $STUDQT{'32000011'}[1]['04'] = '0'; $STUDQT{'32000012'}[0] = 'fname'; $STUDQT{'32000012'}[1] = 'mname'; $STUDQT{'32000012'}[2] = 'lname'; $STUDQT{'32000012'}[3] = 'Sex'; $STUDQT{'32000012'}[1]['01'] = '0'; $STUDQT{'32000012'}[1]['02'] = '0'; + + ; $STUDQT{'32000012'}[1]['03'] = '0'; $STUDQT{'32000012'}[1]['04'] = '0'; #-------------------------------------------- @sorted = sort { "$STUDQT{$a}[3] $STUDQT{$a}[2] $STUDQT{$a}[0]" cmp "$ +STUDQT{$b}[3] $STUDQT{$b}[2] $STUDQT{$b}[0]" } keys %STUDQT; #-----------------------------------Get The Inputs From User foreach $l (@sorted) { #--------------------------------------------------------------------- +------------------- $STUD_1 = ""; $STUD_1 = "$STUDQT{$l}[1]['02']"; for ($i = 1; $i < $INPUT{'assign'}+1; $i+=1) { if ($INPUT{"AS$i$l"}) { $STUD_1 = "$STUD_1$INPUT{\"AS$i$l\"}"; if (($INPUT{'assign'}) != $i) { $STUD_1 .= "~";} } } $STUDQT{"$l"}[1]['02'] = "$STUD_1"."^"; #Problem print "Values for fist key in an associative array with key('3 +2000011')is = $STUDQT{'32000011'}[1]['02'] <br>\n"; print "Problem is a Value has also some how been assigned to t +he next key in an associative array<br>\n"; print "Values for next array with key{'32000012'} is = $STUDQT +{'32000012'}[1]['02'] <br>\n"; print "--------------------------------<br><br>\n\n"; }

Edit Masem 2001-11-02 - Added CODE tags at start


In reply to associative array problem by Gerryjun

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.