mel awaisi wrote:
Hi,

I have with the help of one of the guys of this list got this script to take an image from one directory and then rename it with the time and date of the image and then store it onto a new directory.

I sotred the image in the cgi-bin, and then tried to run the file, i got errors, when i went to the errorlog i got an error saying:
Prematue end of script header: /home/httpd/cgi-bin.renamer.cgi


Regards,


The script you have written is running as a pseudo-daemon, so you will not want to run it as a cgi script. It should be running constantly, aka run it from a terminal and background it. You need to separate the parts of your app that will always be running, aka the script that grabs the photos and moves them, from the parts that are web viewable, on demand, more than one occurrence, etc. If your updating is only going to be once a minute you might also consider just using cron rather than sleeping for 60 seconds, but this is a design decision.


<snip>


exit if (fork());



This probably doesn't do what you want. Check out:


perldoc -q fork
perldoc -f fork
perldoc perlipc

fork returns the PID of the forked child upon success, and the PID will always be positive so the above will always exit the program, which is naturally not what you want.

while (1) {
 process($check_file) if (-r "$original_dir/$check_file.$suffix");
 sleep 60;
}


Here do you want to pass only the filename sans-suffix? This is a design decision. Later when you strip the subs into libraries you will run into scoping issues. Essentially, ANYTHING used inside the sub should either be created there or passed into it. For instance you might be better off passing in the $suffix, $check_file, etc.


sub process {
 my $file  = shift;
 my ($hour, $min, $mon, $day, $year) = (localtime)[1..5];

perldoc -f localtime 1 or more of your above variables will not be set correctly.

 $year += 1900;
 $mon++;
 my $stamp = "$year$mon$day$hour$min";

print
"renaming $original_dir/$file.$suffix to $new_dir/$file.$stamp.$suffix\n";
rename "$original_dir/$file.$suffix", "$new_dir/$file.$stamp.$suffix"
or warn "couldn't rename file $file to $new_dir/$file.$stamp.$suffix\n";

In warnings like the above you should always include $!, it is a special variable that will tell you why what you were trying to do failed.


Looks like a good start... If you were in my class you would be well on your way to an A, you included the strict/warnings and documentation (two *very* good habits).

http://danconia.org


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to