• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

Perl not reading files.

Background:
The system is a P3 running Win98. Also, I'm using a bash shell, Cygnus Bash to be more precise.

I have a script that runs quite well under HP-UX10.20, but is displaying some odd behavior on the PC. It isn't reading files. I don't get any error messages even when running with the w switch. At first I thought that it was having a problem reading from the CDROM drive. I thought that perhaps I needed to mount the drive, but even when copying files to the same directory in which the script resides, it still can't read the file(s).

Question:
What are some things I should check?
0
pdouglas
Asked:
pdouglas
  • 3
  • 3
  • 2
  • +3
1 Solution
 
andreifCommented:
try this:

open(F, "filename_here") or die $!;
...
close(F) or die $!;

Script must die with error message if something is wrong with file reading.

Just for any case: when you write filename, be careful with backslashes "c:\file\test" will not work! Problem is that
\f \t are special chars. You should use UNIX-type slash "/"

0
 
pdouglasAuthor Commented:
I have exactly the open statement that you suggest. It doesn't die. It's as though it looks in the file, but doesn't actually see anything. One thing I failed to mention is that the file to be read is a binary file. Again, it reads just fine in HP-UX, but within bash... nothing.

0
 
andreifCommented:
please, post your code?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
pdouglasAuthor Commented:
I can't do that.
0
 
ozoCommented:
How are you trying to read the files,
and how do you know it is not reading?
Did you set binmode?
0
 
sushrutCommented:
psouglas,
I understand that you are not allowed to post the code if you are working for some organization.

But you can always post the exact part of the code which opens the file. You can change the file names etc..if you feel like change variables names also.
I personallly do the same thing. This way, my business logic is not open to all but EE can help me to solve the problem.


0
 
pdouglasAuthor Commented:
The file name is passed from the command line when the script is launched. Some of the logic used is:

foreach $<filename> ( @ARGV ){
    if ( $<filename> =~ /<match string>$/ )
       open( FILE, $<filename> ) || die $!;
    .
    .
    .
    }
I've not set binmode.
0
 
ozoCommented:
foreach $filename ( @ARGV ){
    if( $filename =~ /<match string>$/ ){
        open FILE, $filename;
        while( <FILE> ){
            print;
        }
    }
}
0
 
ozoCommented:
foreach $filename ( @ARGV ){
    if( $filename =~ /<match string>$/ ){
        open FILE, $filename or die "Can't open $filename because $!";
        binmode FILE;
        while( <FILE> ){
            print;
        }
    }
}
0
 
inq123Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ/No Refund (reason: ozo's solution likely would lead to further diagnosis of the problem although not likely solving the problem, but OP stopped responding)

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

inq123
EE Cleanup Volunteer
0
 
Computer101Commented:
PAQed - no points refunded (of 150)

Computer101
E-E Admin
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now