Question: Read from file 
Author Message
 Question: Read from file


Quote:
>Hi! I am wondering how you are doing the following in Perl:

>Pascal:

[snip]

Quote:
>for those who didn't understand I just need to read from file by
>lines, 1-st, 2-nd, etc till the end.

open FILE, $filename or die "$!";
while( <FILE> )
   {
   ... #do something
   }

you might like to get:

   Learning Perl
   Randal L. Schwartz & Tom Christiansen
   ISBN 1-56592-284-0
   <URL: http://www.*-*-*.com/ >

good luck :)

--

CGI Meta FAQ <URL: http://www.*-*-*.com/ ;
Comprehensive Perl Archive Network (CPAN) <URL: http://www.*-*-*.com/ >
Perl Mongers Travel Deals! <URL: http://www.*-*-*.com/ ;



Fri, 22 Dec 2000 03:00:00 GMT  
 Question: Read from file


Quote:
> for those who didn't understand I just need to read from file by
> lines, 1-st, 2-nd, etc till the end.

#!/usr/local/bin/perl -w
use strict;

my $filename = '/path/to/your/file';
open(FF, $filename) || die "Cannot open $filename for read: $!";
while(defined(my $line = <FF>))
{
        # do something with $line

Quote:
}

close FF;

or

# open
while(<>)
{
        # do something with $_

Quote:
}

# close

Quote:
> Any ideas? I need it asap.. So plz advise..

If you need it fast, you shouldn't post here. You should get yourself
a good book, and read the documentation that comes with perl. If you
need to ask us how to do something as basic as this every time you
need to code 3 lines, then you will finish your programs somewhere in
the next century, maybe.

Martien
--
Martien Verbruggen                  |
Webmaster www.tradingpost.com.au    | We are born {*filter*}, wet and hungry. Then
Commercial Dynamics Pty. Ltd.       | things get worse.
NSW, Australia                      |



Sat, 23 Dec 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Newbie question : Read configuration file.

2. newbie perl question - reading a file line by line

3. Problem reading large files (dumb question?)

4. Newbie Question: Semantics of reading text files

5. Array/File Read Question

6. File Read/Write Question...

7. a question for perl to read DBF files

8. Problem reading large files (dumb question?)

9. Question to the wise - Reading From File

10. Newbie Q: read and append file question

11. -- Question on Reading Hash Info From A File.

12. Newbie Perl Question - Reading File Info.

 

 
Powered by phpBB® Forum Software