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.
In reply to Re^4: add missing elements and remove duplicates....and some more questions.
by pritesh_ugrankar
in thread add missing elements and remove duplicates....and some more questions.
by pritesh_ugrankar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |