LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-07-2011, 12:58 PM   #1
jt1
LQ Newbie
 
Registered: Jun 2009
Posts: 16

Rep: Reputation: 1
Last monday of each month Perl


Hello LQ,

I am new to Perl scripting and have completed a Perl script. The final part of the script needs to find the last Monday of each month. So if it is August, the script returns 20110829. Does anyone have any idea how to accomplish this via Perl?

Thanks for any help.
 
Old 09-07-2011, 01:55 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
I'm not aware of any "ready-made" way to do it.

Suggestion: write your own function that will:

1. Get specified day/month date value of the last day of the month (e.g. "sep 30 2011")

2. Get day-of-week of that date value

3. Subtract backwards to the preceding Monday

4. Return that (monday's) date value
 
Old 09-07-2011, 02:47 PM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by jt1 View Post
Hello LQ,

I am new to Perl scripting and have completed a Perl script. The final part of the script needs to find the last Monday of each month. So if it is August, the script returns 20110829. Does anyone have any idea how to accomplish this via Perl?

Thanks for any help.
Start from http://datetime.perl.org/wiki/datetime/dashboard .
 
1 members found this post helpful.
Old 09-07-2011, 03:42 PM   #4
rkambli
LQ Newbie
 
Registered: Jun 2009
Posts: 6

Rep: Reputation: 0
With thousands of Perl Modules available I am sure you can find something similar in good datetime manipulation module.

Assuming you are using Linux if you cal call one liner shell script from perl here it is:
Just tested for Sep-11 and Oct-11.


Code:
$ cal -m 9 2011 | cut -c1-2 | sed "/^$/d" | tail -n 1
26
$ cal -m 10 2011 | cut -c1-2 | sed "/^$/d" | tail -n 1
31

$perl -e "system('cal -m 10 2011 | cut -c1-2 | sed "/^$/d" | tail -n 1')"

Last edited by rkambli; 09-07-2011 at 04:08 PM.
 
Old 09-07-2011, 04:16 PM   #5
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Actually, Sergei Steshenko made an *excellent* suggestion. I'd encourage you to check out the date/time manipulation tools available at the link he gave you!

IMHO .. pSM
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: CodeWeavers CEO names himself employee of the month for 175TH consecutive month LXer Syndicated Linux News 3 08-13-2010 05:55 PM
Running a job the first monday of the month? yanik Linux - General 12 03-05-2008 06:08 PM
transform month number to month name in php ALInux Programming 1 11-09-2005 11:45 AM
Starting day of month, month length chrisk5527 Programming 2 03-03-2004 05:03 PM
bloody monday aizkorri General 2 05-19-2003 06:45 AM


All times are GMT -5. The time now is 11:03 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration