I am trying to change some setting in a script (perl) but i do not understand what does the following statemnet meant:

sub dirlog
 $mypath     = "/xxx/xxx/";
 $logpath    = "/xxx/xxx";
 $dirlogfile = "randomdir.log";
 $interval   = "0"; # The days that the random dir will be kept;

 @tmpoutput = ("one","two","three","four","five","six","seven","eight","nine");
 srand(time ^ $$);

 $cmd="mkdir $tmp_dir";
 system "echo $cmd > $mypath/cmd; chmod a+x $mypath/cmd;";
 system $cmd;

 $cmd="chmod 777  $tmp_dir";
 system "echo $cmd > cmd; chmod a+x cmd;";
 system $cmd;

 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
 if($mon < 10) 	
    $mon = "0$mon";
 if($mday < 10) 
    $mday = "0$mday";
 $month = ($mon + 1);   ##because $mon start from 0##
 if(!open(DIRLOG, ">>$logpath/$dirlogfile"))
  {    print "Content-type: text/html","\n\n";
    print "Can not APPEND $logpath and $dirlogfile !\n";
 print DIRLOG $tmp_dir,"\$",$month,"\$",$mday,"\$",$year,"\n";

 if(!open(DIRLOG, "<$logpath/$dirlogfile"))   {
    print "Content-type: text/html","\n\n";
    print "Can not read $dirlogfile !\n";

i wish to know what are the statements highlighted in red means

thanks in advance,

It means that the dirlog variable contains a string literal value. The value is randomdir.log

The other two statements are attempting to:
1. to append (add-on to the end of) a file
2. read from a file

On failure they print messages and then exit.

The other two statements are openingfiles (one file each) for appending and reading. After they succeed, DIRLOG is the filehandle for writing or reading from the file. Then print DIRLOG "blah.."; writes some text to the end of the file, and close(DIRLOG) closes the file.

The third red statement opens the file for reading. Then @dir_lines = <DIRLOG>; reads the entire file, line-by-line, into @dir_lines. Then DIRLOG is closed.

The arrows, >> and <, indicate whether the file is opened for appending to the end or reading. (A single > is for writing-over.)


Thanks to all of you who replied..I had fixed the problem : )


This article has been dead for over six months. Start a new discussion instead.