Solved

Perl not reading files.

Posted on 2002-05-16
11
180 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
stftime format 4 56
grep that displays 4 lines above & 1 line below of what's found 10 82
Perl Frameworks 1 93
Perl: How to add backslashes to every period in a string 1 22
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…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

832 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