perl replace awk strftime

Hi Everyone
i have a perl file below, one of the line is convert the pcho time to human readable format.

$value=`awk 'BEGIN{print strftime("%c",1273236600)}' | tr -d '\n'`;

if image, if i have lots of pcho time value in a file, if i use this awk, strftime, then tr -d to remove the \n, then assign it to the variable, this process is very slow.

any way to improve it? like perl has built in function, instead of `` the awk.

Thanks

If you are looking for the equivalent of this -

awk 'BEGIN{print strftime("%c",1273236600)}'

in Perl, then you may want to use the "POSIX" module, which includes the strftime function -

perl -MPOSIX -le 'print POSIX::strftime("%c", localtime 1273236600)'

The POSIX module is part of Perl's standard distribution, atleast on *nix systems. Otherwise CPAN is your one-stop shop.

tyler_durden

1 Like

for awk, use printf, instead of awk|tr, for my file with 35k lines, it saves me around 12 seconds. :b:

use POSIX instead of awk, it saves me around 2 mins and 30 secs (2.30mins) :eek: :eek: :eek: :eek: :eek:

so you can image, each line in that file, has many many time conversation, plus lots lots lines, it really saves lots of time.

Thank tyler :b::b: