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

I must not be asking it right

@new_array = ("$element", "$element1", "$element2", "$element3", "$element4", "$element5") ;

if @new_array has any elements that are the same

then discard it to trash
otherwise, if all the elements are different
then continue running program with @new_array containing those different elements

Originally posted as a Categorized Question.

  • Comment on Clarify I want to discard the set of elements if there are any duplicates.

Replies are listed 'Best First'.
Re: Clarify I want to discard the set of elements if there are any duplicates.
by toddprof (Initiate) on Jul 13, 2002 at 22:54 UTC
    Discard "it" to trash means discard entire @new_array to trash

    Originally posted as a Categorized Answer.

Re: Clarify I want to discard the set of elements if there are any duplicates.
by ackohno (Scribe) on Jul 14, 2002 at 06:12 UTC
    another way:
    @rray=(1,2,2,3,3,3,4,4,4,4); for(@rray) { $seen{$_}++; } @nodups=keys %seen; print "@nodups\n";
    The down side is that it looses original order.

    Originally posted as a Categorized Answer.

Re: Clarify I want to discard the set of elements if there are any duplicates.
by DamnDirtyApe (Curate) on Jul 14, 2002 at 00:59 UTC
    #! /usr/bin/perl use strict ; use warnings ; my @arr = qw| one two three four five | ; my %element_count = () ; foreach ( @arr ) { $element_count{$_}++ ; } foreach ( values %element_count ) { undef @arr if $_ > 1 ; }

    Originally posted as a Categorized Answer.