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

Hello, I hope this is a simple question for you PERL Guru's...I've been working a script(with lots of help from all of you) that currently does the following:
1. creates a sub-directory
2. writes a .htaccess file in the new dir
3. writes a .htgroup file in the new dir
4. writes a .htpasswd file in the new dir
5. writes a upload.html file in the new dir
6. writes a upload.pl file in the new dir
7. chmods the .pl file 755

the problem that has me scratching my head is, how can I set the script to automatically adjust the $basedir in the cgi script to match the current, newly made, sub-directory?

Here is the part of the script that's driving me mad:
# Create PERL file... open(FILE, ">$basedir$q_brieftitle/upload.pl") || &diedebug("$header C +ould not create file $basedir$q_brieftitle/answerfile: $! . It's poss +ible that your web server will not let me create files even if I own +the directory. If you have chmodded $basedir$q_brieftitle/ to 777 and + you are still getting this message, then you will need to create you +r files by hand. :( $footer"); flock(FILE, 2); &get_date; print FILE <<'EOF'; #!/usr/bin/perl $basedir = "/path/to/base/dir/"; $allowall = "yes"; $theext = ".gif"; $donepage = "up2.html"; ## DO NOT EDIT OR COPY BELOW THIS LINE ## use CGI; $onnum = 1; while ($onnum != 11) { my $req = new CGI; my $file = $req->param("FILE$onnum"); if ($file ne "") { my $fileName = $file; $fileName =~ s!^.*(\\|\/)!!; $newmain = $fileName; if ($allowall ne "yes") { if (lc(substr($newmain,length($newmain) - 4,4)) ne $theext){ $filenotgood = "yes"; } } if ($filenotgood ne "yes") { open (OUTFILE, ">$basedir/$fileName"); print "$basedir/$fileName<br>"; while (my $bytesread = read($file, my $buffer, 1024)) { print OUTFILE $buffer; } close (OUTFILE); } } $onnum++; } print "Content-type: text/html\n"; print "Location:$donepage\n\n";"; EOF close(FILE);

The EOF leaves the code alone and doesn't crash the main program...but I need to learn a way to make the $basedir the same as the $basedir$q_brieftitle in the above code. Thank you

Replies are listed 'Best First'.
Re: Generating a current basedir
by extremely (Priest) on Sep 27, 2000 at 08:48 UTC

    Yay you got Heredocs! now just do this:

    print FILE <<'MOF'; # code MOF print FILE qq[\$basedir = "/$basedir";\n]; print FILE <<'EOF'; # rest of code EOF

    If you don't like qq you could do the IMHO uglier: print FILE "\$basedir = \"/$basedir\";\n";

    HTH! =)

    --
    $you = new YOU;
    honk() if $you->love(perl)

Re: Generating a current basedir
by little (Curate) on Sep 27, 2000 at 07:12 UTC
    Hello again,
    as far as I see, you have not only to write a new file, but also to put specific information in that. Did you have a look on RE: CGI Question, which was a reply to your former post?
    You are facing the task, to manipulate the output. So you can read a file and change the contained data or compose the file from , let's say 'static' elements and those you are putting in by runtime.(just like using templates)
    Have a nice day
    All decision is left to your taste