Solved

Perl not reading files.

Posted on 2002-05-16
11
171 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now