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

Hello, just starting down the road of perl, and I need to get this figured out. I'm trying to make an addition to some code so that it checks the file size prior to stating the upload message. here is the script for upload
#!/usr/bin/perl use strict; use CGI qw(:standard); my(@parameters) = param; my $work = ""; my $value = ""; my $company = param('cmdSubmit'); $company = substr($company, 8); my $file = "Response ".param('txtAppNumber')." R".param('txtRevID').". +txt"; foreach my $fieldName (@parameters) { $value = param($fieldName); $value=~s/%/%25/g; $value=~s/\n/%0D%0A/g; $value=~s/\r//g; $value=~s/=/%3D/g; $value=~s/&/%26/g; $work = $work.$fieldName."=".$value."&"; #$work = $work.$fieldName."=".param($fieldName)."&"; } $work = substr($work, 0, length($work)-1); open(F, ">C:\\wamp\\www\\Web Forms\\Data\\Critique\\$company\\$file") +|| die "Cannot create $file\: $!"; #while($work=~s/\n/%0D%0A/){} #while($work=~s/\r/%0D%0A/){} print F $work; close(F); my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtim +e, $ctime, $blksize, $blocks) = stat($file); print header; print "<p>Congratulations! Upload operation successful. You can now +close your browser.</p>"; #print $size<p>size</p>; # print "<p>$file</p>";
you can see here at the bottom that I'm not able to pull out my filehandle object array variables... If I can just get the filehandle variables to show up then I can use a simple IF statement... any help is appreciated as I'm still really new to perl.. Thanks, k

Replies are listed 'Best First'.
Re: issue with checking file size
by almut (Canon) on Mar 13, 2008 at 16:58 UTC

    Try using the full path, i.e. stat("C:\\wamp\\www\\Web Forms\\Data\\Critique\\$company\\$file").

      Thanks, that got me closer now it's saying no file in that directory, which leads me to believe that I'm not locating the correct file... or maybe I need to identify it better in someway. as right now I'm just using a variable that holds the file information thanks for the help.
        now it's saying no file in that directory, which leads me to believe that I'm not locating the correct file...

        Not sure I understand. What exactly is saying "no file in that directory", and what do you mean by locating the file?

        AFAICT, the code writes the content of $work to a file which is created with the path

        "C:\\wamp\\www\\Web Forms\\Data\\Critique\\$company\\$file"

        Presuming the writing of the file succeeded, you should be able to successfully stat() the file afterwards, if you use the exact same path that you used to create the file...

        So, have you checked whether the file gets created/written at all?  Is the $company component of the path a valid (existing) directory?  Do you have appropriate permissions to write the file?  Is there an error message when trying to open the file?

        I'd start debugging with printing out the path to see what the variable parts coming from the form ($company\$file) were set to... Also, you can make your life a little easier, if you assign the path once to some variable, which you then use everywhere, i.e. in the open(), the corresponding error message, the stat(), in debug prints, etc. For example:

        ... my $path = "C:\\wamp\\www\\Web Forms\\Data\\Critique\\$company\\$file" +; # print STDERR "$path\n"; # debug open(F, ">", $path) or die "Cannot create '$path': $!"; print F $work; close(F); my $size = (stat $path)[7]; ...