There has been some debate at our local perl mongers group about when to meet this month, given that we meet on the second Tuesday of the month.

From: Oliver Paukstadt <***> Reply-To: Stuttgart Perl Mongers <stuttgart-pm@pm.org> To: Stuttgart Perl Mongers <stuttgart-pm@pm.org> Subject: Re: [Stuttgart-PM] Treffen DIESE Woche On Mon, 2009-04-06 at 18:59 +0200, Rolf Schaufelberger wrote: > > > > Um das mal dauerhaft und stilgerecht zu lösen : > > > > perl -MDateTime -e ' for (1..20 ) { my $d=DateTime- > > >new(year=>2009,month=>4,day=>$_); if ( $d->weekday_of_month ==2 +&& > > $d->day_of_week ==2 ) { print "$_\n"; last; }}' > > 14 > > Couldn't resist: perl -MDate::Calc=:all -le 'print Date_to_Text(Nth_Weekday_of_Month_Year(2009,4,2,2))' Gruss Oliver

Modules? Not for golf. I came up with this:

perl -le'{@l=localtime($t-=((localtime$t)[3]-1)*86400);$t+=(($l[6]<3?7 +:14)-$l[6]+2)*86400;$t<time?($t+=2592000,redo):print$..localtime$t}'

128 chars not counting perl -le and not counting the surrounding single quotes. I am sure you can do better ;-)

Rules: no modules; if the second Tuesday of the current month has passed, give the second Tuesday of the next month. No requirements on the output format except it must show the correct year, month and day (in any unambiguous order).

update: using gmtime instead of localtime gives 119 chars:

perl -le '{@l=gmtime($t-=((gmtime$t)[3]-1)*86400);$t+=(($l[6]<3?7:14)- +$l[6]+2)*86400;$t<time?($t+=2592000,redo):print$..gmtime$t}'

update 2: joint result of #perlgolf (mtve,shmem), 92 chars:

perl -le 'sub f{gmtime$_*86400}$_+=30while($_+=9+7*(($x=(f$_-=(f)[3]-1 +)[6])>2)-$x)*86400<time;print~~f'

In reply to (Golf) Next second Tuesday by shmem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.