in reply to text processing
The first method is probably the most common and easiest to think of. At the top of the loop, skip lines that you don't want
while (<DATA>) { next if ! /^DATA/; # ...
Another common first step might be to throw away the first N lines
<DATA> for 1 .. 3; while (<DATA>) { # ...
Sometimes it gets more complicated and you need to check a state variable against multiple lines. I won't give you an example of that abstract case but I will show you what some people do:
The above has a micro-optimization which you should avoid unless you need it. Essentially, it avoids paying the penalty of checking to see if we are in the good data against all lines and starts a new loop with only the processing we care about.my $found_start_of_data; while (<DATA>) { last if $found_start_of_data; # ... some complex code that sets the flag } while (<DATA>) { # ... }
The final method I will share is where you extract or eliminate what you don't want.
As you can see, there are many ways to do what you are looking to accomplish. If you don't understand something, please ask.# Extract my ($want) = $data =~ m{(some_regular_expression)}; # Eliminate $data =~ s{some_regular_expression}{};
Cheers - L~R
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: text processing
by DAVERN (Initiate) on Apr 22, 2014 at 17:49 UTC | |
by InfiniteSilence (Curate) on Apr 22, 2014 at 18:27 UTC |