ww has asked for the wisdom of the Perl Monks concerning the following question:
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:\>
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parallel processing two arrays with different numbers of elements
by tobyink (Canon) on Sep 14, 2013 at 21:10 UTC | |
by LanX (Saint) on Sep 14, 2013 at 23:09 UTC | |
by tobyink (Canon) on Sep 15, 2013 at 08:23 UTC | |
by ww (Archbishop) on Sep 15, 2013 at 12:21 UTC | |
Re: Parallel processing two arrays with different numbers of elements
by farang (Chaplain) on Sep 15, 2013 at 00:56 UTC | |
Re: Parallel processing two arrays with different numbers of elements
by Random_Walk (Prior) on Sep 14, 2013 at 21:51 UTC |
Back to
Seekers of Perl Wisdom