View Full Version : how to check and compare in a loop - problem.

11-26-2009, 05:03 PM

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.

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.


11-27-2009, 09:14 AM
finally, finally, I got it.

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


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum