473,404 Members | 2,174 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,404 software developers and data experts.

File Descriptor Errors in Active State Perl

I am new to using Active State Perl, I've use Perl on Linux and Unix systems and the same thing on unix systems don't work with active state and I am perplexed. I wrote the code below and I am getting seven loops of Can not open shawneechamber.txt for reading: Bad file descriptor.

Has anyone had this problem? I am on xp and installed v5.8.7 build for MSWIN32-x86

I am having the same problem at work and at home. I thank you for your help in advance.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. #define variables
  5. my $File = 'shawneechamber.txt';
  6. #my $OutFilePath = 'C:\PerlApp\DataOut\';
  7. #my $InFilePath = 'C:\PerlApp\DataIn\';
  8. #my $OutFileExt = ".csv";
  9. my $lineno = 1;
  10. #my @indata;
  11.  
  12. #open file for reading
  13. open (FILE, "<$File") or die ("Can not open $File for reading:  $!.\n");
  14. binmode(FILE);
  15. #@indata = <FILE>;
  16. while (<FILE>) {
  17. print $lineno++;
  18. print "Can not open $File for reading:  $!.\n";
  19. }
  20. close FILE;
  21.  
Sep 10 '07 #1
8 2598
numberwhun
3,509 Expert Mod 2GB
I am new to using Active State Perl, I've use Perl on Linux and Unix systems and the same thing on unix systems don't work with active state and I am perplexed. I wrote the code below and I am getting seven loops of Can not open shawneechamber.txt for reading: Bad file descriptor.

Has anyone had this problem? I am on xp and installed v5.8.7 build for MSWIN32-x86

I am having the same problem at work and at home. I thank you for your help in advance.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. #define variables
  5. my $File = 'shawneechamber.txt';
  6. #my $OutFilePath = 'C:\PerlApp\DataOut\';
  7. #my $InFilePath = 'C:\PerlApp\DataIn\';
  8. #my $OutFileExt = ".csv";
  9. my $lineno = 1;
  10. #my @indata;
  11.  
  12. #open file for reading
  13. open (FILE, "<$File") or die ("Can not open $File for reading:  $!.\n");
  14. binmode(FILE);
  15. #@indata = <FILE>;
  16. while (<FILE>) {
  17. print $lineno++;
  18. print "Can not open $File for reading:  $!.\n";
  19. }
  20. close FILE;
  21.  
Well, just to note, in the Windows world, you do not need the shebang line in your regular scripts. It is ignored by the Windows version of Perl.

It looks like your open statement is defined correctly, but considering the error, I am wondering if the file is there or accessible. Check the path to it (it is defined as current directory) and check permissions to see if you can read it.

Regards,

Jeff
Sep 10 '07 #2
I have full access to the shawneechamber.txt file.
Sep 10 '07 #3
numberwhun
3,509 Expert Mod 2GB
I have full access to the shawneechamber.txt file.
Ok, well it is something to do with where the file is then. I ran code very similar to yours and it worked fine. I cannot see your system to see what's wrong, unfortunately.

Is the file in the same directory as the script? If not, then you need to specify the full path to the file.

Regards,

Jeff
Sep 10 '07 #4
The file is in the exact same sub directory as the script.

I also re-ran it with absolute path and I got the same error.
Sep 10 '07 #5
numberwhun
3,509 Expert Mod 2GB
The file is in the exact same sub directory as the script.

I also re-ran it with absolute path and I got the same error.

I am wondering if you are actually seeing the error you think you are. I ask because you have the following print statement inside of your while loop:

Expand|Select|Wrap|Line Numbers
  1. print "Can not open $File for reading:  $!.\n";
  2.  
Try taking that out and re-run it and see what happens.

Regards,

Jeff
Sep 10 '07 #6
That was it. Thanks Jeff.
Sep 10 '07 #7
numberwhun
3,509 Expert Mod 2GB
That was it. Thanks Jeff.
Your welcome! And by the way, Welcome to TSDN!

Regards,

Jeff
Sep 10 '07 #8
KevinADC
4,059 Expert 2GB
There is no need to increment a scalar to know which line of the file is being operated on, perl is already doing that in the background with the special variable $. (dollar sign dot)

Expand|Select|Wrap|Line Numbers
  1. open (FILE, "<$File") or die ("Can not open $File for reading:  $!.\n");
  2. while (<FILE>) {
  3.    print "Line number: $.\n";
  4. }
  5. close FILE;
$. is a read-only value.
Sep 10 '07 #9

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

Similar topics

1
by: Patrick LeBoutillier | last post by:
Hi all, I'm trying to perform read and write I/O on a socket file descriptor received for another process via a Unix Domain Socket. In trying to understand all this I came up with a small test...
6
by: pembed2003 | last post by:
Hi all, Given something like: std::ofstream out_file("path"); how do I extract the file descriptor from out_file? Is it possible? What I want is to extract the file descriptor and then pass...
6
by: Siddharth Taneja | last post by:
Hi, I have a very simple prg over here, trying to read the lines of a file #include <iostream> #include <fstream> #include <iostream> #include <string> using namespace std;
9
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent...
1
by: Geoff Cox | last post by:
Hello, I have a few hundred zip files (each one has 1 MS Word doc in it) in the c:\docs folder I run the following script and get "bad file descriptor" after the first doc file has been...
8
by: Steve Thompson | last post by:
Hello all, I was wondering the differnced there were betwee Active State's python and the open source version of python. Would I have to unistall my opend souce python? Additonally, how does...
4
by: Claire DURAND | last post by:
Hi, I try to open a distant (not local) XML file in PHP to read an RSS feed. I can open an HTML page and read it with the file() function. But as soon as I try with a RSS feed instead of...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.