in reply to pondering array population

Whoop!

thanks for the replies, people

I didn't know there was a grep function in Perl!

sub change_punch_process { my %transactions; my @numbers; foreach (sort ($q->param)) { if (/^([0-9]+)/) { push (@numbers,$1) unless grep /\b$1\b/, @numbers; } } print "<br><br>@numbers"; }

As, grantm said, I kept putting in the same numbers over and over.

IMO, a hash would be overkill. I just need the numbers to append my CGI variables.

That grep statement should work right?

At least it is so far.

Thanks again!

Elam Ooops! didn't see your reply sensate. Thanks.

Replies are listed 'Best First'.
Re: Re: pondering array population
by chromatic (Archbishop) on Nov 22, 2002 at 01:21 UTC
    IMO, a hash would be overkill.

    Far less than repeatedly grepping through an array with regular expressions. Either the number exists in the hash or it doesn't. The check takes the same amount of time regardless of the number of elements in the hash (modulo hash bucketing, a subject I really don't want to discuss). With a grep, every new number you add to the array will be checked, every time. The regex is worse, because it has to compile the regex for each parameter and fire up the regex engine for every number checked.

    On the other hand, if you mean "it would be overkill for me to use a hash because I don't understand them and I do understand grep," that makes sense. Except now you do know why to use a hash. :)