473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Questions regarding filehandler

35
Hi guys,
I am handling some upload functions in perl. And I got a problem that I really don't know how to figure it out.
Here is that. I have two files, basically they have the same code in the upload part. But one is working fine, one is not working. I got this error:

binmode() on closed filehandle UPLOADFILE at /spare/WWW/cgi-bin/uploadLindegrenCurrent.pl line 62, <$fh> line 1.
readline() on unopened filehandle at /spare/WWW/cgi-bin/uploadLindegrenCurrent.pl line 63.

I compare the upload parts between these two files, I cannot tell the difference. Could you guys be so kind to give me a hand.

Appreciate that!!!

Here is the code:
Expand|Select|Wrap|Line Numbers
  1. ......
  2.  
  3. use Tie::File;
  4.  
  5. $upload_dir = "../uploadTest"; 
  6.  
  7. $query = new CGI;
  8.  
  9. $data_file="lindegrenChoice.cgi"; 
  10.  
  11. open(DAT, $data_file) || die("Could not open file!"); 
  12.  
  13. @raw_data=<DAT>; 
  14.  
  15. tie @line, 'Tie::File', $data_file or die("Can not open file!"); 
  16.  
  17. .......
  18.  
  19. for($i=1; $i<=$count; $i++){  
  20.    if($current eq $sname[$i]){
  21.      $filename =~ s/.*[\/\\](.*)/$1/; 
  22.      @exten = split('\.', $filename);  
  23.      $filetype = ".";  
  24.      $filetype .= $exten[1];  
  25.      $newfilename = "current_lindegren";  
  26.      $newfilename .= $filetype;  
  27.      $upload_filehandle = $filename;  
  28.      $line[$i-1]="$i|$sname[$i]|1|1|$filetype"; 
  29.  
  30.      open UPLOADFILE, ">$upload_dir/$newfilename"; 
  31.      binmode UPLOADFILE;  
  32.      while (  <$upload_filehandle> )      {   
  33.      print UPLOADFILE;    
  34.      }     
  35.      close UPLOADFILE;   
  36.     }
  37.    else {
  38.        if($scurrent[$i]==0){
  39.          $line[$i-1]="$i|$sname[$i]|$sexist[$i]|0|$stype[$i]";
  40.       ##   print "line $i-1 is $line[$i-1] <br>";
  41.        }
  42.        else{ 
  43.          $line[$i-1]="$i|$sname[$i]|0|0|$stype[$i]";
  44.        }
  45.    }
  46.  } 
  47. close(DAT); 
  48.  
  49.  
Dec 6 '07 #1
4 2480
numberwhun
3,509 Expert Mod 2GB
Hi guys,
I am handling some upload functions in perl. And I got a problem that I really don't know how to figure it out.
Here is that. I have two files, basically they have the same code in the upload part. But one is working fine, one is not working. I got this error:

binmode() on closed filehandle UPLOADFILE at /spare/WWW/cgi-bin/uploadLindegrenCurrent.pl line 62, <$fh> line 1.
readline() on unopened filehandle at /spare/WWW/cgi-bin/uploadLindegrenCurrent.pl line 63.

I compare the upload parts between these two files, I cannot tell the difference. Could you guys be so kind to give me a hand.

Appreciate that!!!

Here is the code:
Expand|Select|Wrap|Line Numbers
  1. ......
  2.  
  3. use Tie::File;
  4.  
  5. $upload_dir = "../uploadTest"; 
  6.  
  7. $query = new CGI;
  8.  
  9. $data_file="lindegrenChoice.cgi"; 
  10.  
  11. open(DAT, $data_file) || die("Could not open file!"); 
  12.  
  13. @raw_data=<DAT>; 
  14.  
  15. tie @line, 'Tie::File', $data_file or die("Can not open file!"); 
  16.  
  17. .......
  18.  
  19. for($i=1; $i<=$count; $i++){  
  20.    if($current eq $sname[$i]){
  21.      $filename =~ s/.*[\/\\](.*)/$1/; 
  22.      @exten = split('\.', $filename);  
  23.      $filetype = ".";  
  24.      $filetype .= $exten[1];  
  25.      $newfilename = "current_lindegren";  
  26.      $newfilename .= $filetype;  
  27.      $upload_filehandle = $filename;  
  28.      $line[$i-1]="$i|$sname[$i]|1|1|$filetype"; 
  29.  
  30.      open UPLOADFILE, ">$upload_dir/$newfilename"; 
  31.      binmode UPLOADFILE;  
  32.      while (  <$upload_filehandle> )      {   
  33.      print UPLOADFILE;    
  34.      }     
  35.      close UPLOADFILE;   
  36.     }
  37.    else {
  38.        if($scurrent[$i]==0){
  39.          $line[$i-1]="$i|$sname[$i]|$sexist[$i]|0|$stype[$i]";
  40.       ##   print "line $i-1 is $line[$i-1] <br>";
  41.        }
  42.        else{ 
  43.          $line[$i-1]="$i|$sname[$i]|0|0|$stype[$i]";
  44.        }
  45.    }
  46.  } 
  47. close(DAT); 
  48.  
  49.  
I would check to ensure that the variable $newfilename is getting set properly by say, using a print statement on it before it is used. If it is a null variable, then the open() will fail, thus resulting in a closed file handle.

Regards,

Jeff
Dec 6 '07 #2
casybay
35
Thanks for your prompt reply, Jeff. After upload, the new file does be created under the correct upload path, however, with size zero. And I check the error log, I got the errors that I listed above.
I would check to ensure that the variable $newfilename is getting set properly by say, using a print statement on it before it is used. If it is a null variable, then the open() will fail, thus resulting in a closed file handle.

Regards,

Jeff
Dec 6 '07 #3
numberwhun
3,509 Expert Mod 2GB
Thanks for your prompt reply, Jeff. After upload, the new file does be created under the correct upload path, however, with size zero. And I check the error log, I got the errors that I listed above.

Ok, did you check the variable I mentioned with a print statement to ensure that it is getting set properly? Also, in your script, please be sure and set the pragma's "use strict" and "use warnings". These will help you iron out initial issues that are recurring in just about everyone's scripts, before you post here.

Regards,

Jeff
Dec 6 '07 #4
KevinADC
4,059 Expert 2GB
change this line:

open UPLOADFILE, ">$upload_dir/$newfilename";

to:

open UPLOADFILE, ">$upload_dir/$newfilename" or die qq{Can't open "$upload_dir/$newfilename" : $!};
Dec 7 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: ppiman | last post by:
Hello, I was wondering if any one out here is dealing with a PALM System called Agile and has some experience with the Agile SDK. If so can you email me, I have a question on the SDK. Also if...
1
by: Jim | last post by:
Hi, with the logging module, I am using the FileHandler formatter. Is there a setting to stop the logger from putting the same message more than once? So it would say: Message whatever...
0
by: A. Wiebenga | last post by:
Hi all! I am a student at the Hogeschool van Arnhem en Nijmegen in Holland. I am currently involved in a research project regarding Reflection. Purpose of the research project is to document...
1
by: Hans-Jürgen Schönig | last post by:
hello ... i am running into a couple of questions regarding materialized view logs. my goal is to take data from an oracle database and replicate it to some remote data store (maybe some other...
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
1
by: fuzzylollipop | last post by:
I want a FileHandler to only log a single level say for example logging.INFO, and nothing else. do I need to create a custom Handler for this or is this doable with some magic that is not...
4
by: Drew | last post by:
I posted this to the asp.db group, but it doesn't look like there is much activity on there, also I noticed that there are a bunch of posts on here pertaining to database and asp. Sorry for...
1
by: Kenneth Love | last post by:
I have a Python logging config file that contains a RotatingFileHandler handler. In the args key, I have hard-coded the log filename. Everything works great. However, I find that I now need to...
16
by: =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post by:
Hi, I am using Visual C# window to dispaly a set of questions with their answers. The users should be able to move to the next question by clicking on next button. I am going to use only one panel...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.