Solved

Perl not reading files.

Posted on 2002-05-16
11
196 Views
Last Modified: 2010-03-05
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
Comment
Question by:pdouglas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 6

Expert Comment

by:andreif
ID: 7013821
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
 

Author Comment

by:pdouglas
ID: 7013903
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
 
LVL 6

Expert Comment

by:andreif
ID: 7013911
please, post your code?
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

Author Comment

by:pdouglas
ID: 7013938
I can't do that.
0
 
LVL 84

Expert Comment

by:ozo
ID: 7015219
How are you trying to read the files,
and how do you know it is not reading?
Did you set binmode?
0
 
LVL 1

Expert Comment

by:sushrut
ID: 7015643
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
 

Author Comment

by:pdouglas
ID: 7015930
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
 
LVL 84

Expert Comment

by:ozo
ID: 7018017
foreach $filename ( @ARGV ){
    if( $filename =~ /<match string>$/ ){
        open FILE, $filename;
        while( <FILE> ){
            print;
        }
    }
}
0
 
LVL 84

Expert Comment

by:ozo
ID: 7018021
foreach $filename ( @ARGV ){
    if( $filename =~ /<match string>$/ ){
        open FILE, $filename or die "Can't open $filename because $!";
        binmode FILE;
        while( <FILE> ){
            print;
        }
    }
}
0
 
LVL 8

Expert Comment

by:inq123
ID: 9510414
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
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 9550786
PAQed - no points refunded (of 150)

Computer101
E-E Admin
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question