Loading ...
Sorry, an error occurred while loading the content.

Calculation ??

Expand Messages
  • Gordon Stewart
    Hi - Im a bit stuck (i ll try & figure it out tonight) - But if anyone can spot it easily, can you let me know .. Basically, The script scans a file, comparing
    Message 1 of 1 , Sep 3, 2001
    • 0 Attachment
      Hi - Im a bit stuck (i'll try & figure it out tonight) - But if anyone can spot it easily, can you let me know ..

      Basically,

      The script scans a file, comparing 1 number with numbers in the file to work out what section of the file to scan/search.


      $ird is the number im trying to find..
      $ara[6] is from the file being read - Compared to $ird

      It reads from the file ok, - The $min & Max are worked out correctly (to find out what point in the file my 'account' / $ird is located..

      However, - my $mid figure drops down to below where my $ird figure is, & it SHOULD increase - to scan the next / 'higher number' part of my file.

      But it doesnt.

      Can anyone easily spot why it doesnt increase ?

      ------------------

      $check=1;
      $max=0;
      $min=0;

      while ($check eq 1) {

      open INF, "<jul2001.csv" or die "can't open schools.dat65 : $!";
      $size = -s INF;
      if ($max < 1){$max = $size;}

      $mid=int((($max-min)/2)+$min); #halfway between min&max

      $count=0;

      # flock(INF,2);

      seek(INF,$mid,0);
      $bytes = read INF, $buffer, 100000, 0;
      (@araa)=split(/\n/,$buffer);
      close(INF);
      print "<CENTER>Start = $start - Size = $size<BR>Midsize = $mid<\/CENTER>\n";

      pop (@araa); # gets rid of the start / end 'half-lines'
      shift (@araa);

      @ara = split(/,/,$araa[0]); #ara 6 is the account-number im comparing to

      $gr=0;

      $maxcount=0;
      foreach $line (@araa){

      $ara[6] =~ s/^0//; #chops off leading zero

      # print "<BR>'$ara[6]' $count $line<BR>\n";

      if ($gr eq 0){
      print "'$ara[6]' '$ird' '$mid'<BR>\n";
      $gr=1;

      }

      $check=0;

      if ($ird < $ara[6]){
      $max=((($mid-$start)/2)+$start); #reduces the $max figure
      $check=1;
      }
      if ($ird > $ara[6]){
      $min=($max-(($max-$mid)/2));
      $check=1;
      }


      $count++;
      }
      }
    Your message has been successfully submitted and would be delivered to recipients shortly.