Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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 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 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.

In reply to Trudging along the learning perl path. by Anonymous Monk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (11)
    As of 2019-05-22 21:20 GMT
    Find Nodes?
      Voting Booth?
      Do you enjoy 3D movies?

      Results (140 votes). Check out past polls.

      • (Sep 10, 2018 at 22:53 UTC) Welcome new users!