ellem has asked for the wisdom of the Perl Monks concerning the following question:

It seems a lot of my current questions revlve around changing text. Sorry I'm not getting this stuff, but consider this code:
#!/usr/bin/perl -w use strict ; my $date eq localtime ; print $date ;
this produces
Thu Aug 23 12:00:01 2001
I'd like it to produce
Thu, Aug 23, 2001
how?
--
lmoran@wtsgSPAM.com
print "\x{263a}"

Replies are listed 'Best First'.
Re: Changing output
by dragonchild (Archbishop) on Aug 23, 2001 at 21:48 UTC
    There are 3 ways I can think of off the top of my head, depending on what your assumptions are about the text. The way I would do it is:
    my @date = split ' ', $date; $date = "$date[0], $date[1] $date[2], $date[4]";
    Someone, of course, is going to post a nifty regex to do it. That could look something like:
    $date =~ s/^(\w+) (\w+) (\d+) \S+ (\d+)$/$1, $2 $3, $4/;

    ------
    /me wants to be the brightest bulb in the chandelier!

    Vote paco for President!

Re: Changing output
by thraxil (Prior) on Aug 23, 2001 at 21:48 UTC

    i hope you mean "my $date = localtime;"

    as is, it doesn't print anything.

    do a 'perldoc -f localtime' to learn more about the function. you probably want to call it in list context and extract the fields that you want.

    anders pearson

      yeah, yeah... must be a bug in the slashcode here -- I was using Netscape 6 to post with -- my '=' key is broken -- I had my assistant type it in for me -- TMTOWTDI, but only some of them are right...
      --
      lmoran@wtsgSPAM.com
      print "\x{263a}"
Re: Changing output
by Hanamaki (Chaplain) on Aug 23, 2001 at 22:52 UTC
    CPAN is your friend:
    On CPAN you will find a lot of well tested modules for date manipulation. In your case I would like to advise you to use Date::Manip.
    #!/usr/bin/perl -w use strict; use Date::Manip; my $date = UnixDate(scalar localtime,'%a, %b %d, %Y'); print "$date\n";
    It is never too early learning to use CPAN.
    Hope that helps,

    Hanamaki
Re: Changing output
by Cine (Friar) on Aug 23, 2001 at 21:54 UTC
    see man strftime. use POSIX qw(strftime) to import it into perl.

    T I M T O W T D I