Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: convert month number to month name

by AnomalousMonk (Monsignor)
on Aug 30, 2012 at 14:26 UTC ( #990770=note: print w/ replies, xml ) Need Help??


in reply to Re: convert month number to month name
in thread convert month number to month name

Shaveta_Chawla wants 8 to convert to 'Aug', so the code should really be:

>perl -wMstrict -le "my $months = 'JanFebMarAprMayJunJulSepAugOctNovDec'; my $month = 8; printf q{'%s'}, substr($months, $month*3, 3); " 'Aug'


Comment on Re^2: convert month number to month name
Download Code
Re^3: convert month number to month name
by Anonymous Monk on Aug 30, 2012 at 14:34 UTC
     printf q['%s'], unpack('x' x ($month * 3) . 'A3', 'JanFebMarAprMayJunJulSepAugOctNovDec');
Re^3: convert month number to month name
by roboticus (Canon) on Aug 30, 2012 at 14:37 UTC

    AnomalousMonk:

    Hmmm ... why not map *all* of 'em to Aug?

    my $months = 'AugAugAugAugAugAugAugAugAugAugAugAug'; my $month = 8; printf '%s', substr($months, $month*3, 3);

    Then we could simplify it a bit:

    my $month = 8; printf '%s', substr('Aug'x12, $month*3, 3);

    ;^)

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      It's true that the specification for mapping of indices other than 8 is undefined, so your further refinements are useful.   ++ to you, sir, and well played!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990770]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2014-07-30 11:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (230 votes), past polls