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. -
#!/usr/bin/perl
-
use warnings;
-
use strict;
-
#define variables
-
my $File = 'shawneechamber.txt';
-
#my $OutFilePath = 'C:\PerlApp\DataOut\';
-
#my $InFilePath = 'C:\PerlApp\DataIn\';
-
#my $OutFileExt = ".csv";
-
my $lineno = 1;
-
#my @indata;
-
-
#open file for reading
-
open (FILE, "<$File") or die ("Can not open $File for reading: $!.\n");
-
binmode(FILE);
-
#@indata = <FILE>;
-
while (<FILE>) {
-
print $lineno++;
-
print "Can not open $File for reading: $!.\n";
-
}
-
close FILE;
-
8 2598
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. -
#!/usr/bin/perl
-
use warnings;
-
use strict;
-
#define variables
-
my $File = 'shawneechamber.txt';
-
#my $OutFilePath = 'C:\PerlApp\DataOut\';
-
#my $InFilePath = 'C:\PerlApp\DataIn\';
-
#my $OutFileExt = ".csv";
-
my $lineno = 1;
-
#my @indata;
-
-
#open file for reading
-
open (FILE, "<$File") or die ("Can not open $File for reading: $!.\n");
-
binmode(FILE);
-
#@indata = <FILE>;
-
while (<FILE>) {
-
print $lineno++;
-
print "Can not open $File for reading: $!.\n";
-
}
-
close FILE;
-
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
I have full access to the shawneechamber.txt file.
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
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.
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: -
print "Can not open $File for reading: $!.\n";
-
Try taking that out and re-run it and see what happens.
Regards,
Jeff
That was it. Thanks Jeff.
That was it. Thanks Jeff.
Your welcome! And by the way, Welcome to TSDN!
Regards,
Jeff
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) - open (FILE, "<$File") or die ("Can not open $File for reading: $!.\n");
-
while (<FILE>) {
-
print "Line number: $.\n";
-
}
-
close FILE;
$. is a read-only value.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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;
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |