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

hash definition:

foreach my $name (@name_list) { my @fields = qw(fname lname); my ($sc_id, @names) = split /\,/, $name; @{$sc{$sc_id}}{@fields} = @names; }

loop definition:

foreach my $sc_id (keys %sc) {

i've tested all the variables and arrays involved and everything is defined unitl you enter that loop??

Replies are listed 'Best First'.
Re: loop criteria not accessable in loop??
by bliz (Acolyte) on Aug 16, 2000 at 20:23 UTC
    i cut and paste, and wrap it a little bit with some variable definitions to make it work, and it works just fine... nothing wrong with the code or the scope handling of $sc_id... -- bliz
      Now that you have described what you did, could you post your solution for everyone to see? It would probably be nice for jptxs to see what works for you. :-)

      Mick
        the only thing I did was assign values to all those date vars and such that he accesses, and values into the associative array.. no actual changes to his code... I was just saying that his code works.. but sure... I mean.. if it helps.. whatever.. :)
        $sc{1}="bob"; $sc{'eatit200'}="jane"; $sc{'testCINDY'}="cindy"; ($SMONTH,$SDAY,$SYEAR,$SHOUR,$SMINUTE,$EDAY,$EYEAR,$EHOUR,$EMINUTE)=(1 +,2,3,4,5,6,7,8,9); foreach my $sc_id (keys %sc) { # Oracle wil not let me put in that '0' at the start; all call_id's +will start with '7' my $call_id = sprintf "7%02d%02d%02d%02d%02d%07d%02d%02d%02d%02d%02d +",$SMONTH,$SDAY,$SYEAR,$SHOUR,$SMINUTE,$sc_id,$EDA my $status = "scheduling"; my $temp_record_statement = qq! INSERT INTO SC_APPT (CONTACT, CALL_ID, SC_ID, CONT_PHN, AP_START, AP_END, STATUS, COMPAN +Y, TRANS_ID, APPT_TYPE, REP_EMAIL, ADD_ST, ADD_STATE, ADD_CITY, ADD_ZIP +) VALUES ('system_reserve', $call_id, $sc_id, 8003069329, '$start_time', '$en +d_time', '$status', 'Quest Software', $trans_id, 'Internal', 'Joanna', 'placeholder', 'NJ', 'Montclair', 9 +99999999) !; print $temp_record_statement, "\n"; print $sc_id, "\n"; #$dbh->do("$temp_record_statement") || dienice("320 Couldn't execute + statement: $temp_record_statement $sc_id" . $sth- }
        I hope that helps... like I said.. I didn't really change anything.. it just worked to start with.. I was just pointing out that his problem was something different that what he was describing... -- bliz
        Well, what he's saying is that he could not reproduce jptxs's problem because the code that was originally published does work if you include enough to make it even make sense!

        See the part that's broken is the part that jptxs didn't tell us about. That's a common help-desk nightmare. I understand how people fall into that trap: it's a complex system, and they don't know what's broken, so they throw random parts of it at experts and say "is this broken?". As we kept saying, no, this part is not broken. That's life.

        -- Randal L. Schwartz, Perl hacker

Re: loop criteria not accessable in loop??
by merlyn (Sage) on Aug 16, 2000 at 20:16 UTC
      the SQL statement generated during the loop uses the value $sc_id from the loop definition and bombs out because it is undefined. that's what showed me at first, then i looked at everything else that was going on in there and realized it was undefined the whole time. i placed prints throughout the lop and it seems to be undefined the whole time.
        Do you mean "undefined", or undef? It can't be undef if you are walking through the keys of a hash. What value does it have at the top of the loop?

        -- Randal L. Schwartz, Perl hacker