On Sep 25, Kredler Stefan said:

>I'd like to match numbers and add them to an array if the array does not
>contain the number. 

You'd want to use a hash, not an array.

>let's assume $part[1] can hold the values in consecutive order e.g. 5, 1005,
>5, 2000.... then 
>
>next if  (grep /$part[1]/, @tnumlist);
>           push @tnumlist,$part[1];

You don't want a regex there.  That will give you false positives.  You'd
want to use

  next if grep $_ == $part[1], @tnumlist;

But that will do more work than necessary.  You really want to use a hash.

>if we reverse the order and $part[1] holds 1005, 5, 2000... then of course
>the above expression would fail to add 5 to the array. 

Because of the regex.  You don't want a regex.  Just use a hash:

  # I don't know what your loop is
  # but do this:
  $seen{ $part[1] } = 1;

Now, you can access the numbers by doing:

  @list = keys %seen;

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to