Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: How do I remove the duplicates from the array?

by PetreAdi (Acolyte)
on Sep 26, 2013 at 06:23 UTC ( #1055785=note: print w/ replies, xml ) Need Help??


in reply to Re: How do I remove the duplicates from the array?
in thread How do I remove the duplicates from the array?

Very good

But i need

@output = ( -20, , ,1, , , ,9,3, ,-4, 5, ,20); @output1 = ( 10, , ,9, , , ,1,3, , 5, 5, ,30); $#array==$#array1==$#output==$#output1


Comment on Re^2: How do I remove the duplicates from the array?
Download Code
Replies are listed 'Best First'.
Re^3: How do I remove the duplicates from the array?
by choroba (Canon) on Sep 26, 2013 at 07:30 UTC
    Please, be more precise. Even if Perl can "do what you mean", sometimes you have to be careful.
    @long = (1, 2, 3, 4, 5); @sparse = (1, , , 4, ); @short = (1, 4); print "Equals\n" if $#long == $#sparse; print "Shorter\n" if $#short == $#sparse;
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Update: Never mind the below for farang had already showed that above.

      I /GUESS/ OP has a issue of keeping track of missing values and display of them. So, undef (ideally; else nothing, '') could be used for the missing values. Format the display with whitespace as needed.

Re^3: How do I remove the duplicates from the array?
by farang (Chaplain) on Sep 26, 2013 at 07:09 UTC

    In that case you can add an else block to the code generating the arrays @output and @output1 in choroba's code.

    my (@output, @output1); for my $i (0 .. $#array) { if (exists $hash{ $array[$i] } and $array1[$i] == $hash{ $array[$i] }{highest}) { push @output, $array[$i]; push @output1, $array1[$i]; } else { push @output, ''; # or use spaces ' ' here push @output1, ''; # or whatever you want } }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055785]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (15)
As of 2015-07-31 20:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (281 votes), past polls