JJB has asked for the wisdom of the Perl Monks concerning the following question:

I have been using system("date >> /var/log/run.history"). Now I want to put that date info into $date
$date = system(date); does not do it.
How do I code statment to capture date & time to $date????

Replies are listed 'Best First'.
Re: capture system date to $date
by Limbic~Region (Chancellor) on Jun 20, 2004 at 15:10 UTC
    JJB,
    Might I suggest using localtime instead:
    print HISTORY scalar localtime; my $date = localtime;
    To answer your original question, you need to use backticks or qx;
    my $date = `date`;
    Cheers - L~R
Re: capture system date to $date
by jeffa (Bishop) on Jun 20, 2004 at 15:11 UTC
Re: capture system date to $date
by mpeppler (Vicar) on Jun 20, 2004 at 15:13 UTC
    $date = localtime;
    is the simplest, although you could also use
    $date = `date`;
    if you really wanted to (you might need to chomp that last one to get rid of the trailing \n).

    Michael

Re: capture system date to $date
by vek (Prior) on Jun 20, 2004 at 18:13 UTC

    system only returns success or failure, not the results of the actual command. As others have pointed out, if you really want to shell out you could have used backticks instead. Having said that, you really don't need to use the shell at all. localtime will give you exactly what you need.

    -- vek --