0 Replies - 1597 Views - Last Post: 09 October 2007 - 09:26 AM

#1 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6824
  • View blog
  • Posts: 31,470
  • Joined: 10-May 07

Write to a file

Posted 09 October 2007 - 09:26 AM

Description: place into a directory & execute.Write text, or a list of files into a log file, using perl!
#!/usr/local/bin/perl
# Written by #2pencil 10/09/2007

# Construct the current date.
($Second, $Minute, $Hour, $Day, $Month, $Year) = localtime(time);
$Month = $Month + 1; # Increment month by 1.
$LongYear = $Year + 1900; # Set $LongYear.
if($Year >= 100) {
	$Year = $Year - 100;
}
$Day = sprintf("%02d",$Day);
$Month = sprintf("%02d",$Month);
$Year = sprintf("%02d",$Year);
$Hour = sprintf("%02d",$Hour);
$Minute = sprintf("%02d",$Minute);
$Second = sprintf("%02d",$Second);

$currentDate = $Year . $Month . $Day;
$archiveDate = $LongYear . $Month . $Day;
$currentTime = "$Hour$Minute$Second";

open (MYFILE, '>>data.txt');
print MYFILE "$currentDate $currentTimenn";

$dir="../log";
opendir DH, $dir or die "Cannot open $dir:";
while($file=readdir DH) {
	if($file =~ /(.$)/) {
		$name=$file;
	}
	else {
		$name=$file;
		print MYFILE "Downloaded ".$name."n";
        }
}
close (MYFILE);



Is This A Good Question/Topic? 0
  • +

Page 1 of 1