in reply to Strange crash - any ideas?

Here is a larger code example - the array @testDateRows has the series of dates that I will be testing - in this case close to a thousand days.
The array @algTickers has all of the names of the data files that will be looked at - several thousand are in there.

When I set it to close after it runs once (tmpCounter > 0), then it works great that one time. It will output all the tickers quickly and it doesn't complain.
When I set the tmpCounter to 1, as it is below, meaning that it runs through the outer loop twice, then I see issues in there for every single spot.
I get the error "Use of uninitialized value in concatenation (.) or string at" some line number in the thing. (it refers to the line number where the open is trying to take place)

This would make me think that since the names are derived from pulling out the filenames of a directory, then the "." and ".." snuck into the array. But I have accounted for their removal in the code that populates that array, and I have output that array to a file to look at the data and it is all correct.

What is wrong with the code below that would allow it to work perfectly one time through the loop, and then the next time through the loop (and every time after that) fail?
I also haven't figured out why at some point it will also clear the screen out - at this level of iteration it doesn't do it, but it will if I get rid of the if statement that will exit.
my $tmpCounter = 0; for(@testDateRows){ if($tmpCounter > 1){ exit; } @tmpArr = split(',',$_); $formattedName = $tmpArr[0]; #iterate through all the tickers for(@algTickers){ $strTickerName = $_; #there is an open call in here that works, I commented it out to see i +f I could still reproduce the problem # open... print "$strTName:$formattedName\n"; #now we need to load the a file $strAlg = ''; open(ALGFILE,"/A/sub/$strTName") or die "can't open th +e asub file: $strTName : $!\n"; while(<ALGFILE>){ $strAlg .= $_; } close(ALGFILE) or die "can't close the asub file: $str +TName :$!\n"; } $tmpCounter++; }


-------------------------------------------------------------------
There are some odd things afoot now, in the Villa Straylight.

Replies are listed 'Best First'.
Re: Re: Strange crash - any ideas?
by AssFace (Pilgrim) on Oct 20, 2003 at 02:40 UTC
    This seems to have resolved the problem. Changing the for loop so that it had:
    for $ticker (@algTickers){ #use $ticker for anything for this spot in the array }
    instead of
    for(@algTickers){ #use $_ into a var and then use that var for this spot in the array }
    This must have been something I missed as I was learning about "$_" out of a for loop - I must have only used it in straight loops and not nested loops up until now. Checked the camel book and in the foreach section it does say that each $_ is a reference, which I knew, but I don't see any code there that is clearing out that spot in the array... not sure why it was doing it, but this seems to have resolved the issue and then the ensuing side effects.

    Now I need to uncomment a lot of lines now to confirm that this fixes the issue.


    -------------------------------------------------------------------
    There are some odd things afoot now, in the Villa Straylight.
      Add the following to the top of your perl script:
      use strict; use Data::Dumper;
      And then add print Dumper(\@algTickers); before and after your for loop, as this will inspect your array and see what has been changed.