Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing a line by bytes or characters

Status
Not open for further replies.

lresides

Programmer
Aug 9, 2001
7
US
Hi,
I have a file which was supplied by an outside vendor. The file contains no end-of-line type characters. When it is viewed via emacs for instance, it is one big (very big) line.

I know that a logical record exists every 250 characters. I would like to insert a carriage return or end-of-line character every 250 characters so that I have one logical record per line.

Can anyone point me in the right direction? I've been searching various links for a while but haven't run across anything similar. Thanks, Leigh

 
The [tt]read[/tt] function will let you specify a number of bytes to read from a filehandle. So the following
Code:
while ( read(FILE, $buf, $bytes) ) {

    print "$buf\n";
}
will read [tt]$bytes[/tt] number of bytes from the FILE filehandle into $buf at a time and print with a trailing newline.

jaa
 
Thank-you!! I love it when this stuff works! I'm just dabble right now in perl, but it is fun when I'm not pulling out my hair. Thanks again, Leigh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top