Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

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

First of all it is a good thing you want to learn experiencing but, BUT! trying to do something without using the simpler, acclaimed way (an hash for uniqueness) maybe is not so good idea, worst if you are beginning. The satandard way is a FAQ infact (infaq?)

Anyway it is possible for example using the smart match operator (it is sperimental) which syntax is ~~ see Smartmatch-Operator and act, in the form $scalar ~~ @array like if array contains scalar

my @arr = (0,1,2,3,1,2); my @uniq; foreach (sort{$a<=>$b} @arr){ unless($_ ~~ @uniq){push @uniq, $_} } print join ' ', @uniq;

This is very similar to another existing builtin tool any from List::Util (update: fixed from Utils to Util) core module:

use List::Util qw(any); my @arr = (0,1,2,3,1,2); my @uniq; foreach my $it (sort{$a<=>$b} @arr){ unless(any{$_ == $it}@uniq){push @uniq, $it} } print join ' ', @uniq;

I say this because it is very important and crucial to know which Perl tool to use for a task: this can save hours of your precious time: get the habit to read across perldoc to know everyday more: functions tutorials, core modules.. perldoc save your day!

Then, instead of start spending several hours trying to get uniqness without using an hash it will be by far better to read some good manual like ModernPerl.pdf the free book, or to get a copy if the even old PerlCookbook (a must have to get a wide panorama of solutions and fields to play with).

I say this because me too i'm somehow a Perl-just-for-fun (I use at work too but when conceiled and i just show perl result and benefits when i've done).

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: Trudging along the learning perl path. -- wrong path? :=) by Discipulus
in thread 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":



  • 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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (5)
    As of 2019-05-24 18:17 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Do you enjoy 3D movies?



      Results (151 votes). Check out past polls.

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