in reply to System call problem

Its generally considered good perl style to avoid doing system calls unnecessarily. In your case: instead of doung a system call to date, use localtime (or some other perl time function/module). Its generally less prone to unexpected errors and in many cases significantly faster to do it all in perl:
my ($day,$mon,$year)=(localtime(time))[3,4,5]; my $date=sprintf("%0d%02d%02d",$year+1900,$mon+1,$day);
a quick benchmark on my system shows the localtime method is 39 times faster than the system call to date method:
 localtime:  4 wallclock secs ( 3.10 usr +  0.06 sys =  3.16 CPU) @ 30622.78/s (n=96768)
   sysdate: 31 wallclock secs ( 0.38 usr  3.65 sys + 11.15 cusr  2.36 csys = 17.54 CPU) @ 767.25/s (n=3092)
using
#!/usr/bin/perl -w use strict; use Benchmark; timethese(0, { sysdate => "chomp( my \$date = `date +\%Y\%m\%d` );", localtime => 'my ($day,$mon,$year)=(localtime(time) +)[3,4,5]; my $date=sprintf("%0d%02d%02d",$year+1900,$mon+1,$day);', });

Replies are listed 'Best First'.
Re: Re: System call problem
by Gloom (Monk) on Mar 08, 2001 at 20:40 UTC
    exact ! I totaly agree with you, I avoid extra process creation when it's possible ( in complience with perlstyle I think :)
    _______________________
    Hope this helps