Solved

Perl not reading files.

Posted on 2002-05-16
11
160 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
Comment Utility
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
Comment Utility
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
Comment Utility
please, post your code?
0
 

Author Comment

by:pdouglas
Comment Utility
I can't do that.
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
How are you trying to read the files,
and how do you know it is not reading?
Did you set binmode?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 1

Expert Comment

by:sushrut
Comment Utility
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
Comment Utility
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
Comment Utility
foreach $filename ( @ARGV ){
    if( $filename =~ /<match string>$/ ){
        open FILE, $filename;
        while( <FILE> ){
            print;
        }
    }
}
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
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
Comment Utility
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
Comment Utility
PAQed - no points refunded (of 150)

Computer101
E-E Admin
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

9 Experts available now in Live!

Get 1:1 Help Now