Perl script variable to read shell command

Solaris 10
Korn shell ksh,

Hi there,

I have figured out to get yesterday's date which is using the below command:
TZ=GMT+24; date +%d-%b-%Y to get the format of 30-Sep-2008 and
TZ=GMT+24; date +%Y%m%d to get the format of 20080930.

I need this two format. In my perl script below I need the variable of $date and $folder to have the above format. Below method don't work. Please help.

--------------------------------------------------------------------------
# FILENAME: collectLog-smtp.pl
# Version : 1.o
# Purpose : Collect log for the specify date
# Changes : n/a
#
# Editable settings
# Variable

my $date = `TZ=GMT+24 date +%d-%b-%Y`;
my $folder = `TZ=GMT+24 date +%Y%m%d`;
#my $date = "30-Sep-2008";
#my $folder = "20080930";

# DO NOT modify the below settings
my $row = "";
my $input = "/jes/dist/sbas-poc/report/" . $folder . "/smtp/smtp.mail.tmp";
my $output = "/jes/dist/sbas-poc/report/" . $folder . "/smtp/smtp.mail.log";

open(INFILE, "$input") or die "Cannot open input file";
open(OUTFILE1, ">$output") or die "Cannot open output file";

while (<INFILE>)
{

# 14x argument
# col[0] = date
# col[1] = timestamp
# col[2] = msg ID
# col[3] = source channel
# col[4] = either destination channel OR log status
# col[5] = either log status OR mail size
# col[6] = either mail size OR sender address
# col[7] = either sender OR rfc;recipient address
# col[8] = either rfc;recipient address OR recipient address

    $row=$_;
    @col    = split /\\s\+/, $row;

    if\( $col[0] eq $date \)
    \{
            print OUTFILE1 "$row";
    \}

}
close INFILE;
close OUTFILE1;
--------------------------------------------------------------------------

You need to chomp the output from backticks; it contains a trailing newline.

Beyond that, if it still doesn't work, it would be most helpful if you could say how it doesn't work.

(In the die message you should probably include the name of the file and the value of $!. -- this improves troubleshooting tremendously.)

I totally agree with era. chomp() the scalars that store the output from the backticks and add the filename and $! to the die message. chomp() should resolve the problem though.

Why do you need to call the date command to get a date?

my $date = `TZ=GMT+24 date +%d-%b-%Y`;
my $folder = `TZ=GMT+24 date +%Y%m%d`;

Since you are using Perl, use Perl's functions to get the date you want:

use POSIX qw(strftime);
my $date   = strftime("%d-%b-%Y", localtime());
my $folder = strftime("%Y%m%d", localtime());

For getting yesterday's date you can follow these simple instructions:
perlfaq4

Thanks for the reply, I am noob in programming actually.

I saw this code from web:
Output is day.month.year (e.g. 31.12.2006):

perl -le '($D,$M,$Y)=(localtime(time-86400))[3,4,5];printf("%.2d.%.2d.%.4d",$D,++$M,$Y+=1900)'

May I know how can I apply to my code?(Is my colleague's code, I am learning to modify it. I need to assign the $date and $folder into yesterday's format)

Please help