Ok, I am basically stuck here:
#!/usr/bin/perl use Data::Dumper; while(<DATA>) { $all_numbers=$_; chomp $all_numbers; @vector=(); @vector = split(/\@/, $all_numbers); $start; @answer; for ( sort {$a <=> $b} @vector) { if( not defined $start or $_ > $start + 1000 ) { push @answer, [ $_ ]; $start = $_; } else { push @{ $answer[-1] }, $_; } } for $i ( 0 .. $#answer ) { print "$i\t [ @{$answer[$i]} ]\n"; } print "//\n"; } __DATA__ 141326478@103194415@50137382@86004442@86004438@86004434@85280835@17916 +134@85280834@86004437@85280832@53250112@50137387@50137380@29223108@25 +694155@86004431 6901075@6901079@34073753@88911904@34073751@91346449@34073757

If I only have 1 line of data, it works perfectly, but If I have these 2, it creates this:
0 [ 17916134 ] 1 [ 25694155 ] 2 [ 29223108 ] 3 [ 50137380 50137382 50137387 ] 4 [ 53250112 ] 5 [ 85280832 85280834 85280835 ] 6 [ 86004431 86004434 86004437 86004438 86004442 ] 7 [ 103194415 ] 8 [ 141326478 ] // 0 [ 17916134 ] 1 [ 25694155 ] 2 [ 29223108 ] 3 [ 50137380 50137382 50137387 ] 4 [ 53250112 ] 5 [ 85280832 85280834 85280835 ] 6 [ 86004431 86004434 86004437 86004438 86004442 ] 7 [ 103194415 ] 8 [ 141326478 6901075 6901079 34073751 34073753 34073757 88911904 +91346449 ] //

What am I doing wrong?

In reply to Re^3: Stuck with manipulating an array by Anonymous Monk
in thread Stuck with manipulating an array by Anonymous Monk

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.