Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Help Parsing A Text File

Reply
Thread Tools

Help Parsing A Text File

 
 
greggiefen
Guest
Posts: n/a
 
      01-03-2007
Hello,

I am new to Perl but have programmed in other languages in school. I
am trying to parse a VERY large text file. I initially tried to load
it all into an array but that seemed to fail due to memory constraints.

This is what i'm trying to do:#!/usr/bin/perl -w

open(OF, "output.txt");

while ($line = <OF>) {

#If a line contains this i wanted it printed so the date will be
included
if($line =~ /Page 1/) {
print $line;
}

#I want all the records regarding Mr. Smith printed. However the
records span multiple lines
if($line =~ /Mr Smith/) {
print $line;

#the lines of the peronsal records end in a line of all asterix
while ($line =~ /[^\*]/) {
print $line;
#do something magical here
}
}

}

What I need to do is to somehow get the perl script to jump to the next
line after printing the current line in the last loop, but still stay
in the loop until it reached the line of all **. If i could get all of
it into an array i could simply incriment the index until i reched the
line of all asterixs.

 
Reply With Quote
 
 
 
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      01-03-2007
greggiefen <> wrote in comp.lang.perl.misc:
> Hello,
>
> I am new to Perl but have programmed in other languages in school. I
> am trying to parse a VERY large text file. I initially tried to load
> it all into an array but that seemed to fail due to memory constraints.
>
> This is what i'm trying to do:#!/usr/bin/perl -w
>
> open(OF, "output.txt");
>
> while ($line = <OF>) {
>
> #If a line contains this i wanted it printed so the date will be
> included
> if($line =~ /Page 1/) {
> print $line;
> }


Is there a question involved?

> #I want all the records regarding Mr. Smith printed. However the
> records span multiple lines
> if($line =~ /Mr Smith/) {
> print $line;
>
> #the lines of the peronsal records end in a line of all asterix
> while ($line =~ /[^\*]/) {
> print $line;
> #do something magical here
> }
> }
>
> }
>
> What I need to do is to somehow get the perl script to jump to the next
> line after printing the current line in the last loop, but still stay
> in the loop until it reached the line of all **. If i could get all of
> it into an array i could simply incriment the index until i reched the
> line of all asterixs.
>


That's what the ".." operator does in scalar context. Try

print if /Mr Smith/ .. /^\*+$/;

Anno
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help parsing a text file William Gill Python 6 09-01-2011 06:38 PM
SAX parsing problem, when element contains text like "[text]" Kai Schlamp Java 1 03-27-2008 08:36 PM
In file parsing, taking the first few characters of a text file after a readfile or streamreader file read... .Net Sports ASP .Net 11 01-17-2006 12:44 AM
Assistance parsing text file using Text::CSV_XS Domenico Discepola Perl Misc 6 09-02-2004 03:55 PM
Help with parsing text file Joey Martin ASP General 2 11-07-2003 10:19 PM



Advertisments