Well, in that case, you might be better off with the pairwise function of List::MoreUtils:
$ perl -Mstrict -Mwarnings -E '
use List::MoreUtils qw{pairwise};
my @x = 0 .. 3;
my @y = map { 10 + $_ } @x;
say for pairwise {
"$a + $b = " . ($a + $b) . "; $b - $a = " . ($b - $a)
} @x, @y;
'
0 + 10 = 10; 10 - 0 = 10
1 + 11 = 12; 11 - 1 = 10
2 + 12 = 14; 12 - 2 = 10
3 + 13 = 16; 13 - 3 = 10
Note how $a holds @x elements and $b holds @y elements. These ($a & $b) are the same special variables used by sort, so don't declare them; they're described in perlvar - SPECIAL VARIABLES - General Variables. You can use them in either order: cf. $a + $b and $b - $a.
-
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.
|