[Perl] Timestamp conversion

Hi,

I have searched, read and tried, but no luck.

I have this code:

#!/bin/perl -w #-d

use strict;
use POSIX qw(strftime);

my $getprpw_list="/usr/lbin/getprpw -l";

my $host = "nbsol151";
my $user = "genadmin";

my %uid;
my %spwchg;
my %upwchg;
my %slogint;
my %ulogint;
my %alock;
my %lockout;

open (GETPRPW, '-|', "$getprpw_list $user");
while (<GETPRPW>) {
        chomp;
        if ( /uid=(.*?),/ ) { my $uid{$host} = $1 }
        if ( /spwchg=(.*?),/ ) { my $spwchg{$host} = $1 }
        if ( /upwchg=(.*?),/ ) { my $upwchg{$host} = $1 }
        if ( /slogint=(.*?),/ ) { my $slogint{$host} = $1 }
        if ( /ulogint=(.*?),/ ) { my $ulogint{$host} = $1 }
        if ( /alock=(.*?),/ ) { my $alock{$host} = $1 }
        if ( /lockout=(.*?)$/ ) { my $lockout{$host} = $1 }
}
close (GETPRPW);

printf "spwchg : $spwchg{$host}\n";

The result is:

spwchg : Thu Feb 12 08:19:32 2009

Which is okay.
But I need to put 4 of those dates, plus some more data , on 1 line.
Therefore I would like to have the date converted to something shorter.
Like:

spwchg : 09-02-12/08:19:32

I tried with localtime and strftime, but it does not work for me.
That is to say, I cannot make it work.

Anybody out there that knows the easiest way to convert
"Thu Feb 12 08:19:32 2009" into "09-02-12/08:19:32" ??

Thanks,

E.J.

One way to do it is as follows:

$
$ cat tsconv.pl
#!/usr/bin/perl
%mon = qw (Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6 Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec 12);
$time = "Thu Feb 12 08:19:32 2009";
($dow,$mth,$dom,$hms,$yr) = split / /,$time;
print "Original Format:\t$time\n";
print "Converted Format:\t";
printf("%02d-%02d-%02d/%s\n", substr($yr,2), $mon{$mth}, $dom, $hms);
$
$ perl tsconv.pl
Original Format:        Thu Feb 12 08:19:32 2009
Converted Format:       09-02-12/08:19:32
$
$

tyler_durden

Thanks a lot tyler_durden.

I tried to feed the splitted data to strftime, but the printf is of course easier as I have the data I need already.

E.J.