http://qs1969.pair.com?node_id=1188013

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Respected Monks,

I've been trying to re learn perl after a long hiatus. Things seem to move along slowly. I'm at a point where I am not quite sure if it's even possible for me to continue with learning as my learning speed is considerably slow.

While using a hash is a preferred way to remove duplicate values, I wanted to play around with perl trying to see if it could be done without using a hash. This is what I came up with.

$ more rem_duplicates.pl use warnings; use strict; my @arr = (29,24,0,24,24,12,0,10,10,19,17,15,13,1,12,12,24); sub del_duplicate { my @sortit = sort{$a <=> $b} @_; my @unique; foreach my $index (0..$#sortit) { --$index; my $current = $sortit[$index]; my $next = $sortit[++$index]; if ($current == $next) { $current = undef; } else { push @unique, $current; } next if $current = undef; } @unique = sort {$a <=> $b} @unique; print "@unique\n"; } &del_duplicate(@arr);

And it seems to work fine.

$ perl rem_duplicates.pl 0 1 10 12 13 15 17 19 24 29 $

My problems are:

1) It took me about 3-4 hours to write this, that too, I had to re re re edit the code several times. Never wrote it in one fell swoop. I did take breaks in between to do some weekend chores though. Oddly enough, the $current = undef came in my mind when I was doing some mundane chore. I had earlier added the next if $current = undef; line just above the  if loop, but then, after about 5 minutes of thinking, I added it where it is right now and it seemed to work. I didn't write this nicely, meaning step by step, just kept changing the code, checking the output, then adding a print command to do some debugging, then changing again...and so on.

2) I had tried the same thing about a week or two ago, still it took me long time to write it. Also the code I wrote today is not identical to what I wrote a week or two ago.

I am not a developer by profession or by vocation. Some folks watch TV, some play games, I solve puzzles and/or play with Perl. Hope is someday, I will be able to write some good Perl code and become a good perl programmer.

But I am totally pissed with my lack of speed, I cannot write stuff in one fell swoop (meaning at one go), I keep re editing stuff many times.

Does this happen with you guys too? Were you too slow and made lots of mistakes as beginners? Or should I take this as a sign that, perhaps, my goal of becoming a good perl programmer is a mere mirage and I should better invest time somewhere else? Your guidance will really be helpful.