I'm looking for a piece of PERL that will return 'true' only on a certain day of the week for a certain time period. For instance between 9pm and 10pm every Wednesday night I want to display 'true' on a page via SSI.

1) Check the day and time 2) If day = Wednesday and time > 9pm and time < 10pm print "true" 3) Else print "false"

That's the logic. I just know too little about Perl to write it myself! Can you help?

AARRRGGGHHHH!!!! Thanks RedRum. I ran the code in the IDE, but did not run it with the -w flag turned on!

Sangiro. Sorry for the mistake. You can use RedRum's code or insert (without the quotes) "my " in front of @ltime = localtime; in the code I gave you and that will fix the error RedRum is talking about. Dennis

Can I add one more complication to my question: What would the code look like if I wanted to display "true" between between 9pm on Wednesday and 6am on Thursday (instead on the original 9-10 on Wednesday)?

btw, "use constant X => 1" is just a cool way of saying "sub X(){1}", which results in a in-lined subroutine

This is just a note, the fact is that i was thinking the same as you about sub x {1}, but an article i saw earlier this month (i dont remember where, but i'll tell you) made me check the following testConstant.pl: [perl]use constant SECONDS_IN_DAY => 60 * 60 * 24; use constant DEBUG_CONST => 0;

There you can see that the constant have been replaced in the print statement while the sub didnt... Note the '???' it indicates that perl optimized away a constant value (and in this case a whole statement...). So i guess it's better to use constants than subs...

As you can see, you cannot usually pass the hash key as a bareword, since it would be treated as a string then. When you use & to disambiguate, the optimizer won't inline your constant. It'll also pass the @_ array to the sub although it has a prototype. The 'right' way to disambiguate is to use an empty argument list or, if the context allows it, to prepend a unary plus.

-- mhx At last with an effort he spoke, and wondered to hear his own words, as if some other will was using his small voice. "I will take the Ring," he said, "though I do not know the way."

i didnt knew it would be optimized with an empty prototyping () and thanks a lot for the explanation, i'm playing with that stuff right now

btw, i didnt forget about your ipv6 golf, but i had a lot of work this week and couldnt play with it before, but i'm coming with a nice solution (nice, sadly because it looks like nobody made it shorter yet)... your code for the IPv6 validation is helping a lot :-)

That would imply: WED ... day ... THU Shouldn't that mean that you should fill in a <= at the dots? Then writing if(WED <= $day && $day <= THU){.. ??? Unless you ment between THU and WED (including the weekend) I'm confused.

But I think you got the idea of my code, and that you're able now to implement your own version.