Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you change environmental vars? 1

Status
Not open for further replies.
Dec 17, 2002
41
US
Here's the problem. I am taking data from an Oracle database, and putting it into a text file. I want to name a directory to put the text files into by using the DATE_LOCAL ENV var. But, the format of the DATE_LOCAL var includes the time like this hr:min:sec. That creates 2 problems: 1. Win file naming conventions won't allow the ":" in folder names and 2. Even if it did, it would create a new folder for each file (I have multiple tables to back up) because the backups would be conducted at different times. Below is some code to help.

The code works to create a directory named folder_name and puts the file $table_Name.txt in it. I want to replace folder_name with the date the backup was conducted without having to change my code for each backup.

while ( my @String = $sth->fetchrow_array) {

#Print out the result
my $data="$table_Name.txt";
mkdir ../Backup Data Files/folder_name");
open(DAT,">>../Backup Data Files/folder_name/$data") || die("Cannot Open File");
print DAT "'";
print DAT join "', '", @String;
print DAT "'";
print DAT "\n";
close(DAT);

}
 
@ltime = localtime;
$ltime[5]+=1900;
$ltime[4]=sprintf("%02d", $ltime[4]+1);
$ltime[3]=sprintf("%02d", $ltime[3]);
$foldername = $ltime[5]."-".$ltime[4]."-".$ltime[3];

@ltime elements:

$ltime[0]
Seconds

$ltime[1]
Minutes

$ltime[2]
Hour

$ltime[3]
Day

$ltime[4]
Month – with January as month 0

$ltime[5]
Year. This has to be added to 1900 to get the actual year

$ltime[6]
Weekday (Sunday is 0, Monday is 1, ...)

$ltime[7]
Day of the year with Jan 1 as day 1

$ltime[8]
1 if DST is in effect in the time zone. 0 if no DST


B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top