Just noodling around and -- Shazam! lightening struck (or maybe it was just that the dim bulb went on) --
but every time I have to process two arrays of differing lengths, in parallel, I have to go hunting for instructions or code-to-cargo-cult and maybe also for those remnants of hair I've just extracted trying to recall a decent approach.
So, does the algorithm implemented in the following code have an accepted name? or is it so dumb, it's known for the forcefulness with which it's been critiqued/criticized (and if so, why)? ...or (by some unlikely chance) novel?
#!/usr/bin/perl use 5.016; use warnings; # Parallel processing of two arrays with different numbers of elements my @arr=qw/a b c d e/; my @bar = qw/12 34 56/; my $i = 0; while ($i<($#arr+2)) { no warnings 'uninitialized'; say "\t \$i: $i"; say "\t\t $arr[$i], $bar[$i]"; ++$i; }
Execution:
C:\>D:\_Perl_\PMonks\parallelArrayProcess.pl $i: 0 a, 12 $i: 1 b, 34 $i: 2 c, 56 $i: 3 d, $i: 4 e, $i: 5 , C:\>
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |