Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://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 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.


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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-28 16:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found