$array1[$k] =~ s/^\s+//; $array1[$k] =~ s/\s+$//; $array2[$l] =~ s/^\s+//; $array2[$l] =~ s/\s+$//;

Maybe preferably use a little helper routine (or even existing code from a module such as Text::Trim):

# modify value in place sub trim { $_[0] =~ s/^\s+//; $_[0] =~ s/\s+$//; } trim($array1[$k]); trim($array2[$l]); # --- or --- # return the trimmed value sub trim { my $s = shift; $s =~ s/^\s+//; $s =~ s/\s+$//; return $s; } $array1[$k] = trim($array1[$k]); $array2[$l] = trim($array2[$l]);

This has the advantage of documenting what's going on (with no extra effort), and if you need to trim a third or fourth time, the code would eventually get more compact.  Also, should you ever want to modify the regex, you'll only have to do it one place, so you'll not risk suffering from the cut-n-paste syndrome (one characteristic of which is that it's not only tedious, but also easy to overlook one of the several supposed-to-be-identical code fragments scattered about, when making modifications).

Also, generally try to avoid the variable name $l. With many fonts, it's difficult to discern $l (dollar-ell) from $1 (dollar-one)...
</nitpick>


In reply to Re^2: compare 2 arrays of strings by almut
in thread compare 2 arrays of strings by sharan

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.