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

I need to have the Date and time MM DD MM HH set to an eviornment variable. If my environment variable is TESTVAR, how do i get perl to get the time and date i want below, into that variable?
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdat) = localtime(time +); $date= sprintf "%02s%02s%02s%02s", $mon+1, $mday, $hour, $min; print "$date";
Thanks

Replies are listed 'Best First'.
Re: Environement variable help
by insensate (Hermit) on Jun 04, 2002 at 19:22 UTC
    Should be pretty simple...try:
    $ENV{TESTVAR}=$date;
    -jason
Re: Environement variable help
by Aristotle (Chancellor) on Jun 05, 2002 at 06:37 UTC

    As insensate said, $ENV{TESTVAR} = $date will do the trick if you want to use the environment variable within your script, or inherit it to the script's children.

    It will not propagate back to the script's caller however. If that's the goal, then the solution is to simply backtick the Perl script - assuming you call it from a shell script and it is called "datescript", TESTVAR=`datescript` would do the trick. Although in that case, you better use date(1) rather than write a custom script - TESTVAR=`date '+%m%d%H%M'`.

    Makeshifts last the longest.