Your problem is poorly specified. When we have to make guesses as to how to derive your output from your input, it is likely that we will guess the simplest thing that could possibly work and do that, or, more likely, just ask for clarification. Since there have already been several of the latter, I'll take a shot at the former.
Using the following specs - for a file with 2 columns of numbers; let's call them pointer and value:
- look for consecutive runs where the value (in the second column) is:
- Greater than 4
- Greater than the value of the previous entries. *** <-- ASSUMPTION
- Print the pointer of the start of the run, the pointer + 50 of the end of the run, and the value of the end of the run
If it was me, I would do something like:
use warnings;
use strict;
my ($start, $lastp, $lastv);
while ( my $line = <DATA> ){
my ( $pointer, $value ) = split /\s+/, $line;
flush() if ( $value <= 4 or $value > 4 && $value < $lastv );
$start = $pointer unless ( defined $start || $value <= 4 );
( $lastp, $lastv ) = ( $pointer, $value );
}
flush();
sub flush {
if ( defined $start ){
printf "%d %d (which is %d + 50) %d\n", $start, $lastp + 50, $
+lastp,
$lastv;
}
undef $_ for ( $start, $lastp, $lastv );
}
__DATA__
109026 3
109027 28
109028 30
116958 15
116960 35
116961 39
116962 70
116963 72
147184 2
147588 1
153087 32
Yields:
109027 109078 (which is 109028 + 50) 30
116958 117013 (which is 116963 + 50) 72
153087 153137 (which is 153087 + 50) 32
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.