in reply to Array undefining istelf?

I see no my's in your code so i'm going to venture to say you're not using strict here. I would add

use strict; use warnings;
to the top of the script and see what develops. It also seems that you are not passing any parameters to your subs and using global variables instead. Passing references to your variables into your subroutine makes your code a little more understandable (because you know what data you will be working due to explicitly passing references to the subroutine).

I'm not trying to be dismissive of your question at all.. but using strict pragma can reveal so many problems you didn't even know existed in your code. If you're serious about learning more perl and becoming exceedingly efficient at coding and debugging it.. then I would strongly reccomend using strict.

Put the strict and warnings after your shebang and correct the errors it displays, then you may have a clearer picture of what's going on in the program. This whole problem could be as simple as mispelling a variable in one place of the program.

This piece of code

foreach(@sof_i) { last if $_=~/^={30}/; ($i_day, $i_month, $i_date, $i_hour, $i_minute, $i_second, $i_ +year)=$_=~/(^\D{3}) (\D{3})\s+(\d{1,2}) (\d{2}):(\d{2}):(\d{2}) (\d{4 +}) sw_eof \[.+\] try / if $_=~m/try/; ($i_con_day, $i_con_month, $i_con_date, $i_con_hour, $i_con_mi +nute, $i_con_second, $i_con_year)=$_=~/(^\D{3}) (\D{3})\s+(\d{1,2}) ( +\d{2}):(\d{2}):(\d{2}) (\d{4}) sw_eof \[.+\]/ if $_=~m/connected/; ($i_socket_status)=$_=~/\[(.*)\]/ if $_=~m/EOF Socket Status/; $sof_to_delete++ } ##This just randomly deletes the first elements of the array for ho +wever many times you did $sof_to_delete++ for ($i=0;$sof_to_delete>0;$sof_to_delete--) {shift(@sof_i);}
confuses me. Of corse your array @sof_i will be empty.. you don't have a condition around $soft_to_delete++; so effectively what your code is doing (unless i'm totally crazy) is
foreach(@sof_i) { $sof_to_delete++; } shift @sof_i for (0..$sof_to_delete)
In turn looping through every value .. doing some regex and then marking it for deletion and then in fact deleting it..,

am I way off base here?

Grygonos

Replies are listed 'Best First'.
Re: Re: Array undefining istelf?
by K_M_McMahon (Hermit) on Feb 27, 2004 at 15:22 UTC
    I will try the use strict and use warning. But as far as the $sof_to_delete, it is incrementing at each iteration of the for (@sof_i) statement, but that for (@sof_i) statement has a last if $_=~/^={30}/; statement which should stop the for statement after about 5 lines. (every 5 lines is a line of =========== .

    -Kevin
      so then the sub would be called multiple times and the ^={30}, is just tellin it to stop for now right? btw, simple print debugging can be very revealing. checking the value interactively as you go through the code. something like
      print $var_to_check; my $dummy = <STDIN>; #so it doesn' fly by in programs that generate lo +ts of output

      Grygonos