how to get the yesterdays date?

Hi All,

Can anybody help me to get the yesterdays date in perl script.

My script is as below

#!/bin/perl -w
$yes=system("TZ=IST+24 date +%d-%m-%Y");
print "$yes\n";

script is writting the date but with 0

pls see the output below

#!/bin/perl -w
$yes=system("TZ=IST+24 date +%d-%m-%Y");
print "$yes";

16-07-2010
0

Appreciate ur help.

Thanks,

If only people started to read the docs before complaining that a function doesn't work as they want. Besides that, it's completely useless to call an external program for some functionality that Perl can provide by itself.

First of all, system() does not return the output of a command, but just runs it. What is returned is the exit status of the command, which is the 0 you're seeing. Second, simple date calculation in Perl:

$ cat date.pl
#!/usr/bin/perl

use strict;
use warnings;
use POSIX qw/strftime/;

my $time1 = time();
my $time2 = time - ( 24 * 60 * 60 );

my $yes1 = strftime '%d-%m-%Y', localtime($time1);
my $yes2 = strftime '%d-%m-%Y', localtime($time2);

print "$yes1\n";
print "$yes2\n";
$ perl date.pl
19-07-2010
18-07-2010

Hi,

Thanks for your quick reply. script is working fine.

Regards,
jam