#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    16
    Rep Power
    0

    While loop confusion


    Hi
    I am accessing a dbf file with lots of records. This is the portion of code where I am having confusion about!
    CODE

    while ($i<=$rdb->last_record)
    {
    my @data = $rdb->get_record($i,"X", "Y"
    if($data[2]<20)
    {
    $comment = "Good";
    wdb->set_record($i,$data[1],$data[2],$comment);
    }
    if($data[2]>20)
    {
    #PLEASE HELP ME FILL THIS PART
    }
    This is what I have to do

    --> If value of Y is less than 20
    -> Write comments as good
    -->If value of Y is 20 or greater
    ->Keep looking until X value is greater than 5
    ->Count number of records until X value 5 is reached--(*)
    ->If number of these consecutive records counted in (*) is greater than 10
    -->write bad_not_fixed to comments
    ->If number of consecutive records counted in (*) is 10 or less
    --> write fixed to comments
    The main reason for my confusion is how do you first finish counting the records(10) and then go back and write? Please help me with this.
    I wold really appreciate it.
    Cheerz
  2. #2
  3. 'fie' on me, allege-dly
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,889
    Rep Power
    6444
    please use [code] or [highlight =perl] tags when posting code, it can only help ...
    perl Code:
    while ($i<=$rdb->last_record) {
       my @data = $rdb->get_record($i,"X", "Y"
       if($data[2]<20) {
           $comment = "Good";
           wdb->set_record($i,$data[1],$data[2],$comment);
           $bad_rec_counter=0;
       }
       if($data[2]>20) {
           $bad_rec_counter++;
           if ($bad_rec_counter>=5) {
               ## DO SOMETHING
           #PLEASE HELP ME FILL THIS PART
           }
       }
    }
    Basically you need to manage some counters in the code to keep track, and when you've done something, reset the counter and start again. Looking at your requirements at the foot of your post doesn't make much sense to me, maybe if you rewrote it to give a clear understanding of what needs to happen, this could help you as well
    --Ax
    without exception, there is no rule ...
    Handmade Irish Jewellery
    Targeted Advertising Cookie Optout (TACO) extension for Firefox
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones


    09 F9 11 02
    9D 74 E3 5B
    D8 41 56 C5
    63 56 88 C0
    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
    -- Jamie Zawinski
    Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
    BIT COINS ANYONE
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    16
    Rep Power
    0
    Basically,

    if i have 50 records, with X,Y and comments column(comments is empty column at start). My motive is based on the values of X and Y column I have to populate comments column.

    If value of X is greater than 20
    then I traverse the Y records till the value of Y reaches 5, If the number of Y records I had to traverse is greater than 10,I write
    bad_not_fixed to the comments column corresponding to Y records traversed upto 5. If the number of Y records is less, I write fixed to comments for the Y records counted.


    In short, count records till Y reaches value of 5, If counted records>10 "comments = bad_not_fixed " else "fixed"
  6. #4
  7. 'fie' on me, allege-dly
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,889
    Rep Power
    6444
    I hear what you're saying, BUT you're still not thinking about it ...
    and X and Y are what ewxactly ...
    Last edited by Axweildr; February 7th, 2010 at 05:55 PM.
    --Ax
    without exception, there is no rule ...
    Handmade Irish Jewellery
    Targeted Advertising Cookie Optout (TACO) extension for Firefox
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones


    09 F9 11 02
    9D 74 E3 5B
    D8 41 56 C5
    63 56 88 C0
    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
    -- Jamie Zawinski
    Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
    BIT COINS ANYONE
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    16
    Rep Power
    0
    X,Y and comments are the 3 column names

IMN logo majestic logo threadwatch logo seochat tools logo