Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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:
    1. Greater than 4
    2. 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

In reply to Re: Sorting the numbers: A little tricky. by thundergnat
in thread Sorting the numbers: A little tricky. by oxydeepu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (7)
    As of 2014-09-20 08:10 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (157 votes), past polls