Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts

    how to check and compare in a loop - problem.

    Hi,

    Been racking my brain on this for for a few days now and I am really stuck.

    arrays, hashes, grep, next and last; I can't seem to work out how any of them can do this.

    Code:
    foreach my $day_number (1..$number_of_days_to_show) {
    
      foreach my $booking (@booking_data){
         ($booking_id, $room_status, $check_in_date, $check_out_date) = split /\// , $booking, 4;
        
    #print qq( booking_id=$booking_id, $room_status = $room_status :iso=$full_iso_date : cid=$check_in_date : cod=$check_out_date<br />  );
        next unless ( $full_iso_date >= $check_in_date || $full_iso_date <= $check_out_date);
    This is for a sort of calendar where each day (1-31) should output. Later code works out if the room is booked or vacant.

    The code above, outpits all the data but, unfortunately it ensures that for each $booking (in the loop), the day 1-31 outputs as well, so I currently show a calendar for the month with days like this, 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10 etc, because there are three values in the @booking_data array.

    I expect that a hash may help but I can't work out what way to build it ie what to put in it.

    any advice on the code or a tip on maybe doing it totally differently, would be gratefully appreciated.


    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #2
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    finally, finally, I got it.

    too a mixture of foreach, a hash a grep and an array. blimey that was a challenge.

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •