Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Accessing Files - Win32

Posted on 1998-09-01
4
Medium Priority
?
215 Views
Last Modified: 2010-03-05
I am having trouble figuring out how to read a file using Perl for Win32.  Here is an example of my code.

$FileName = "d:\Perl\Scripts\testfile.txt"
if ( open ( eFile, $FileName )) {
        $line = <eFile>;
        while ( $line ne "" ) {
           print ( $line );
           $line = <eFile>;
        }
}
close ( eFile );

I have tried several things based on examples from the Learning Perl on Win32 Systems but have had no success.  

Can someone offer some help?

Thanks in advance.
0
Comment
Question by:tyates
[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
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1204659
$FileName = 'd:\Perl\Scripts\testfile.txt';
if( open ( eFile, $FileName ) ){
  ...
}else{
  warn "can't open $FileName because $!";
}
0
 

Expert Comment

by:kaijen
ID: 1204660
Hi,

you could also use '/' (Unix-Style) instead of the bckslash.

This would make:

$FileName = 'd:/Perl/Scripts/testfile.txt';
if ( open ( eFile, $FileName ) )
{
  while ( ( $line = <eFile> ) ne "" )
  {
    print $line;
  }
}
close ( eFile );

or do you want:

  while ( $line = <eFile> )
  {
    print $line if $line ne "";
  }

Best regards,
Kai.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1204661
#or just
print while( <eFile> );
0
 

Accepted Solution

by:
nchen091098 earned 100 total points
ID: 1204662
Your filename needs to escape out the backslashes.

For your first line, use this instead:
$FileName = "d:\\Perl\\Scripts\\testfile.txt";

Otherwise, "\P", "\S", etc will be considered individual characters
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
Six Sigma Control Plans

610 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