Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

turning fixed variable into an array

Status
Not open for further replies.

perlescent

Technical User
Apr 7, 2005
23
GB
here are the values I need to work with

my $dateRequested = 01;
my $numericalMonthRequested = 03;
my $yearRequested = 2007;
my $numberOfNightsRequested = 5;

I need your help please.

How can I run a loop, to created a file for each of the dates,
1st through to 6th?

 
assuming a date in the format
Code:
$string="20070301-5";
($yearRequested, $numericalMonthRequested, $filler, $dateRequested) =unpack ("A4A2A2AA", $string);
HTH
--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Thanks Paul, I can see how that would work in one respect. However, I am not sure how it could work for this.

Having looped through specific files (for bedrooms) and found one that is vacant (filename is Twin_001_2007-04-29) I want then to find out if that room is vacant on the following 5 days, for example.

my choice (I think), is that within the existing loop: -

to loop through those filenames, which are the same but for the '29' and somehow make the date up from an array. Or,
make up the actual filenames that I want to look through and open all of them at once to check their booking status.

for making a booking for one day, I have that code done. I am trying to amend it so that it can check through a number of days, passed by param (my $numberOfDaysToCheck = $query->param('5');

At this point, I am trying to find out the easier way to do this rather than ask for help with actual code, though that may come later. The present code is quite long but if you need to see it I can post it here or, email it to you.

bazz
 
If you're using text files for this you're asking for trouble IMO. This has database written all over it.

Have you inherited this, or are you writing from scratch?






Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
you should probably not be using human readable format for the date, you should be using the time stamp (epoch time) returned from the time function. So your filenames would look like:

Twin_001_1141501746

now it is a simple matter of checking any date in the past or future based on the time. You can still do date comparisons using your date format but you have to use a date module and split up the date into variables or convert the time back into epoch time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top