in reply to How to get 3-letter month abbreviations ?

my ($month) = localtime =~ m#^[^ ]+ (\w{3})#; print $month, "\n";


If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, reply to this node or /msg me to tell me what is wrong with the post, so that I may update the node to the best of my ability. If you do not inform me as to why the post deserved a downvote, your vote does not have any significance and will be disregarded.

Replies are listed 'Best First'.
Re: Re: Localtime
by jdporter (Paladin) on Feb 14, 2003 at 22:54 UTC
    or
    my $month = lc((split ' ',localtime)[1]);
    or
    my @months = qw( jan feb mar apr may jun jul aug sep oct nov dec ) +; my $month = $months[ (localtime)[4] ];

    jdporter
    The 6th Rule of Perl Club is -- There is no Rule #6.

Re: Re: Localtime
by thezip (Vicar) on Feb 14, 2003 at 23:09 UTC

    Absolutely. In scalar context,

    print scalar(localtime), "\n";

    localtime returns a time string like:

    Fri Feb 14 14:53:08 2003

    I never actually realized it until you pointed it out. I always did it the hard way and constructed an array of month names.

    Thanks coruscate++

    Where do you want *them* to go today?
Re: Re: Localtime
by powerhouse (Friar) on Feb 14, 2003 at 22:50 UTC
    Awesome, thank you! One more question, please.

    What I'm trying to do, is get the month, then I'm going to build a popup_menu using CGI.pm that has that months days in it as the values they can select.

    However, know I realize that there must be a module that I might be able to find that already does that, otherwise I'd have to create 12 hashes, one for each month, then call that, depending on the value of the month.

    Ex: jan has 31 days, so the days popup_menu would have 1 - 31 to be selected from. feb has 28, possibly 29... etc.

    Is there a module that does that.

    Sorry for the trouble. I should have realized that 15 mins ago, before I asked the other question.

    Thank you for any module you can think of for me. I am not good with knowing what modules are and so forth.

    thx,
    Richard
      The module Calendar::Simple will do it. Here is how you could use it to get the days in the current month (it gets the last day of the last week of the month):
      use strict; use Calendar::Simple; my $mon = (localtime)[4] + 1; my $yr = ((localtime)[5] + 1900); my @month = calendar($mon, $yr); print $month[-1][-1],"\n";
        Thank you, Tall_Man!

        One more question based on your answer...

        The $month returns just the number of days in that month. If I'm using CGI.pm's popup_menu function, how do I get the 28 days returned because this is Febuary to have 1-28 days in the popup menu? I know I can then get todays date and have that as the default by using -default=>$day.

        I just don't know how to go about putting the values and labels for the days of the month, unless I don't use CGI.pm and just do it this way:

        $counter = 0; $option_List = ""; while ($counter <= $month) { $counter++; $option_List .= qq~<option value="$counter">$counter</option>\n~; } $html_content .= qq~<select name="day" size="1"> $option_List </select> ~;

        But then that would not work for what I'm doing, because I'm using CGI.pm's sticky behavior, so that when they change the date, it will be selected by default.


        Any ideas on how to do it with just a max number(28)?
        thx,
        Richard