read varilble length lines 
Author Message
 read varilble length lines

Newbie alert.. The following is a question that to some may seem simple.
If Newbie questions bother you, then do not read further. Send flames to:

i have a file that is 92,000 lines long. Sometimes more, sometimes less.

I want to read it one line at a time to compare it with grep or someother
array command. However, the lines are of varilble length and I never know
what the length could be. It could be 1 or 255 characters.
both read and sysread seem to require a length option. Is there a
command to read up to the end of the line? I don't want to read each
item and compare it to a newline do I? must be an easier way?

what is the common way to pull a line in one at a time and pass it
to a scalar?

To those that answer with help thank you!

--


Computer Sciences Corporation      |HF: AB6GA 3.905Mhz or 14.241Mhz
In any organization there will always be one person who knows what is going on.
This person must be fired.



Mon, 13 Apr 1998 03:00:00 GMT  
 read varilble length lines
: Newbie alert.. The following is a question that to some may seem simple.
: If Newbie questions bother you, then do not read further. Send flames to:

:
:
: i have a file that is 92,000 lines long. Sometimes more, sometimes less.
:
: I want to read it one line at a time to compare it with grep or someother

-----cuthere-----
#!/usr/local/bin/perl
while ( <> ) {
   print "the line just read was: $_";

Quote:
}

-----cuthere-----

--
Congratulations, a attention good have pretty span. you
jan b schipmolder



Mon, 13 Apr 1998 03:00:00 GMT  
 read varilble length lines
   Newbie alert.. The following is a question that to some may seem simple.
   If Newbie questions bother you, then do not read further. Send flames to:

Not really a good way to start out, expecting people to have a bad
attitude.  We're a pretty nice bunch around here.

   I want to read it one line at a time to compare it with grep or someother
   array command. However, the lines are of varilble length and I never know
   what the length could be. It could be 1 or 255 characters.
   both read and sysread seem to require a length option. Is there a
   command to read up to the end of the line? I don't want to read each
   item and compare it to a newline do I? must be an easier way?

   what is the common way to pull a line in one at a time and pass it
   to a scalar?

What you want to do is open the file for reading, and then use the file
read operator (<>) to get a line at a time.  Something like this:

open FILE, "myfile" or die "Can't open myfile: $!\n";
while (<FILE>) {
    # you've now got a line... do what you want with it

Quote:
}

-spp
--
Stephen P Potter        Pencom Systems Administration         AMP Incorporated

Home: 717-540-0131      Pager: 1-800-759-8888, 547-9561     Work: 717-986-5401
                Systems Administation: It's a Kind of Magic


Thu, 16 Apr 1998 02:00:00 GMT  
 read varilble length lines

Quote:
>What you want to do is open the file for reading, and then use the file
>read operator (<>) to get a line at a time.  Something like this:

>open FILE, "myfile" or die "Can't open myfile: $!\n";
>while (<FILE>) {
>    # you've now got a line... do what you want with it
>}

You forgot to mention the line is available in $_

Ciao,
Brian



Thu, 23 Apr 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Limiting maximum line length during line based read

2. Controlling line length read by <>

3. read last line without reading previous lines, how?

4. how to read in line by line?

5. read line by line

6. read line by line in perl

7. how to read in line by line?

8. How do I read line by line of data from a file using perl

9. how to read a huge file line by line without loading it into memory

10. reading lines from one file and pulling matching lines in another

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

12. Line by line file reading

 

 
Powered by phpBB® Forum Software