Ah, much better! We don't care what your code looks like (actually, that's a lie) so long as you are prepared to take some advice and improve. This is lovely code - there is a ton of room for improvement. ;)

First off, always use strictures (use strict; use warnings;). Don't use $a and $b as variables - they are special (used by sort). Avoid the C style for loop - Perl's for loop is safer, clearer and cleaner.

Generally if you have parallel data try to use a single data structure for it so you don't have to double handle everything with the resultant duplication of code and much greater risk of errors.

Bearing that in mind consider:

use strict; use warnings; my $str1 = "a b c d e f g h i j"; my $str2 = "1 3 45 65 7 89 67 9 8 2"; my @seq = split (' ', $str1); my @arr = split (' ', $str2); my @data = map {[$seq[$_], $arr[$_]]} 0 .. $#seq; my $beg = 0; my $end = 0; for (@data) { last unless $_->[1] < 15; $beg++; } for (reverse @data) { last unless $_->[1] < 15; $end++; } print join (' ', map {$data[$_][0]} $beg .. $#arr - $end), "\n"; print join (' ', map {$data[$_][1]} $beg .. $#arr - $end), "\n";

Perl reduces RSI - it saves typing

In reply to Re^3: chopping the beginning and end of lines in 2 files by GrandFather
in thread chopping the beginning and end of lines in 2 files by heidi

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.