in reply to Re^3: add missing elements and remove duplicates....and some more questions.
in thread add missing elements and remove duplicates....and some more questions.
Hi,
No that was not me.
And I now understand what has happened. So I have changed the code. And you are right, just because my code looks good does not mean it's good.use strict; use warnings; my @arr = (1, 2, 3, 4); sub do_it_all { my $biggest = $_[0] ; foreach my $num (@_) { if ($num > $biggest) { $biggest = $num; } } my $smallest = $_[0]; foreach my $smallnum (@_) { if ($smallnum < $smallest) { $smallest = $smallnum; } } print "\$smallest = $smallest\t\$biggest = $biggest\n"; my @unique = ($smallest..$biggest); print "@unique\n"; } &do_it_all(@arr);
And it now correctly prints:
C:\>perl anomalous_func.pl $smallest = 1 $biggest = 4 1 2 3 4
Update: I have updated the main thread with your observation. Thank you very much. I did a stupid mistake that should have been avoided at all costs.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: add missing elements and remove duplicates....and some more questions.
by Marshall (Canon) on Apr 25, 2017 at 15:10 UTC | |
by pritesh_ugrankar (Monk) on Apr 25, 2017 at 18:48 UTC |