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

I humbly ask the monks greater than me about an error that has been giving me much humility. While humility is fine in some cases, it is not good when your trying to get some thing done...

What I want the snippet of code, that currently is not working, to do is check to see if the user of the upload has a directory on the server, and if they do not, make them one...

The syntax error is: Compilation failed in require at e:\domains\karawachi.com\user\htdocs\upload\default.pl line 13

The code in that file main file (default.pl) is:

#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); push @INC, "e:/domains/karawachi.com/user/htdocs/upload"; package S3DUpload; my $basedir = "e:/domains/karawachi.com/user/htdocs/upload/upload"; my $stylefile = "style/style1.css"; my $datfile = "dat/datfile.dat"; # This next line is where the error: # Compilation failed in require at e:\domains\karawachi.com\user\htdoc +s\upload\default.pl line 13. # Prolly now line 16 or something in this text. require "checkname.pl"; require "displayfiles.pl"; require "handleupload.pl"; require "parsedatfile.pl"; require "printdat.pl"; require "uploadscreen.pl"; require "welcome.pl"; require "upload.pl"; return 1;

I will take the package bit out, maybe, later.

The code in the other file (checkname.pl) is:

#!/usr/bin/perl use strict; use CGI; # Errors should get shown to the browser better here: use CGI::Carp qw(fatalsToBrowser); # checks to see if a user has a directory, # Then makes one if they do not... sub checkname { $name = shift; opendir UPLOAD,"$basedir/$name" or mkdir "$basedir/$name", 777; closedir UPLOAD; #return success, cause you should always have # a return'd value return 1; } # Need this line so that the file may be # gotten with require(); return 1;

Unless I am being evil with my opening of directories (Which I think would cause an error when the function is actually used more than anything), this code should work. Of course I am not really seasoned enough in perl to make that as an accurate judgement.

DakeDesu teh Confused Werewolf.
Year Neo 3102
(Webpages under construction)

Replies are listed 'Best First'.
Re: Problem with require()
by dws (Chancellor) on Dec 19, 2001 at 06:49 UTC
    A couple of problems.

    First, don't end a require'd file with   return 1; Instead, just write   1; or   "hi mom"; or something. Any non-false, non-undef value will do.

    Next, to avoid ambiguity (or, rather, to avoid getting tripped up by precedence), change   opendir UPLOAD,"$basedir/$name" or mkdir ... to   opendir(UPLOAD,"$basedir/$name") or mkdir ... or even better, write   mkdir "$basedir/$name", 0777 unless -d "$basedir/$name"; (and note that octal constants like 0777 require a leading zero).

      Forsooth, dws, you've given this poor petitioner exactly the wrong advice!

      Don't tell acolytes that opendir X,$x or die is dangerous because opendir lacks parens. To the contrary, the entire point of the "and", "or", "xor", and "not" keywords is that they have such low precedence that they are safe to use in just that fashion.

      Remember, being too cautious is just as likely to lead you into a mistake as not being cautious enough.

          -- Chip Salzenberg, Free-Floating Agent of Chaos

      That will teach me to apply C concepts to perl ;)... never knew I did not need the "return" keyword

      Thanks for your solution... I will make sure you get credit (I ALWAYS give credit)

      DakeDesu teh Confused Werewolf.
      Year Neo 3102
      (Webpages under construction)
        That will teach me to apply C concepts to perl ;)... never knew I did not need the "return" keyword

        And when is the last time you successfuly return'd from a #include'd file?

Re: Problem with require()
by joealba (Hermit) on Dec 19, 2001 at 10:47 UTC
    Compilation failed in require at e:\domains\karawachi.com\user\htdocs\upload\default.pl line 13.

    So, your problem is with checkname.pl. Run a perl -c checkname.pl and you'll see your problem. From the looks of your code, you'll see something like:

    Global symbol "$name" requires explicit package name at checkname.pl l +ine 11. checkname.pl had compilation errors.
    Your $name variable is not scoped, and you are running under use strict in that file (which is a Good Thing). Toss a my in front of it, and double-check the rest of your scoping issues.

    One other thing: It's probably better to rewrite:
    push @INC, "e:/domains/karawachi.com/user/htdocs/upload";
    as
    use lib "e:/domains/karawachi.com/user/htdocs/upload";
    Check out the use lib docs