in reply to add missing elements and remove duplicates....and some more questions.

The  do_it_all() functions in the OP and here use methods for determining the biggest and smallest numbers from the argument list that I've extracted and respectively named  do_it_all_1() and  do_it_all_2() below.

c:\@Work\Perl\monks\pritesh_ugrankar>perl -wMstrict -le "do_it_all_1(1, 2, 3); do_it_all_2(0, 1, 2, 3); ;; ;; sub do_it_all_1 { print qq{do_it_all_1: (@_)}; ;; my $biggest = shift @_; foreach my $num (@_) { if ($num > $biggest) { $biggest = $num; } } ;; my $smallest = shift @_; foreach my $smallnum (@_) { if ($smallnum < $smallest) { $smallest = $smallnum; } } ;; print qq{smallest == $smallest, biggest == $biggest}; } ;; sub do_it_all_2 { print qq{do_it_all_2: (@_)}; ;; my $biggest = @_; foreach my $bignum (@_) { if ($bignum > $biggest) { $biggest = $bignum; } } ;; my $smallest = @_; foreach my $smallnum (@_) { if ($smallnum < $smallest) { $smallest = $smallnum; } } ;; print qq{smallest == $smallest, biggest == $biggest}; } " do_it_all_1: (1 2 3) smallest == 2, biggest == 3 do_it_all_2: (0 1 2 3) smallest == 0, biggest == 4
Questions:

(The foregoing is intended as propaganda for a Test::More development approach that might have uncovered these inconsistencies earlier.)

One other small perplexity. You describe the feedback given you regarding the code of the OP as "[t]hat I did not try to address the issue, but circumvented the issue ..." But the "issue" seems to be described in the paragraph beginning "Given a random series of numbers, ...", and your code seems to address this requirement statement directly. (Others have touched on this.) Can you clarify the dissatisfaction of your instructor/TA? It doesn't make sense to me. (The whole business about Linux Mint/Ubuntu/whatever seems entirely irrelevant.)


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: add missing elements and remove duplicates....and some more questions.
by pritesh_ugrankar (Monk) on Apr 24, 2017 at 13:31 UTC

    Hi,

    I think for some reason, it's taking the scalar value of the array as the biggest value. I could be wrong, but just a hunch. I tried again and my script seems to work ok.

    use warnings; use strict; my @arr = (10,10,20,0x47,1,30,45,45); sub do_it_all { my $biggest = shift @_; foreach my $num (@_) { if ($num > $biggest) { $biggest = $num; } } my $smallest = shift @_; 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);

    I added the  print "\$smallest = $smallest\t\$biggest = $biggest\n"; line for verification, and the output I get is the following:

    C:\>perl no_sort.pl $smallest = 1 $biggest = 71 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2 +7 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5 +0 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    Thinkpad T430 with Ubuntu 16.04.2 running perl 5.24.1 thanks to plenv!!

      Hi pritesh_ugrankar. If this was posted by you, then you have recognized the problem I wanted to bring to your attention. If it was not, please run the  do_it_all() function given here with the arguments  (1, 2, 3, 4) and see what you get.

      And just as a general observation, code that looks great and doesn't work is worthless. I've written a lot of code that looked wonderful, but...


      Give a man a fish:  <%-{-{-{-<

        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.

        Thinkpad T430 with Ubuntu 16.04.2 running perl 5.24.1 thanks to plenv!!

      The code looks fine. During edge testing, am having to make 2 line changes.

      my @arr = (1,10,10,20,0x47,30,45,45); sub do_it_all { my $biggest = $_[0]; ... my $smallest = $_[0]; ... }