Perl booboo of the day

Beatnik on 2005-07-14T14:44:37

Moments before I left for home yesterday, I spotted a bug in one of my scripts.. It was stuck in an infinite loop. This morning I found what it was (after merely a minute of looking at my code)...Behold my stupidity:

while (@foo) {..
The thing is that I updated this code from a filehandle read to an array loop.. but in my autopilot mode probably just changed the filehandle (+ diamond operator) with the array.


Ever used the construct?

davebaker on 2005-07-14T15:22:11

I guess you could use the while( @apples ) { ... } construct if you were popping stuff off of @apples in the block. But maybe foreach my $apple (@apples) { ... } is the better way to go unless you want to actually eat all the apples from the array :)

Re:Ever used the construct?

Beatnik on 2005-07-14T15:29:07

Well yes... I usually would go about it like that.. if I have my head on straight :) However, if I've been surviving the day on hourly caffeine injections, there aren't much perl minded brain cells awake and I make booboos like that :)