laziness, impatience, and hubris | |
PerlMonks |
Re: Run if weekendby davido (Cardinal) |
on Jun 14, 2016 at 16:06 UTC ( [id://1165613]=note: print w/replies, xml ) | Need Help?? |
Keeping it simple, localtime returns the day of the week in list context as the field at index 6:
So values of 0 or 6 would represent Sunday and Saturday. Time::Piece, which comes with Perl, presents an object oriented interface into date/time manipulation:
However, you may also decide that it's a better separation of concerns, leading to more generally useful code if you let the code not care about the day of the week, and set up a crontab entry to do what cron does best. Dave
In Section
Seekers of Perl Wisdom
|
|