Page 1 of 1
A Perl beginner's array searcher
Posted: Wed Sep 03, 2008 11:16 pm
by devdavad
delete this account
Re: A Perl beginner's array searcher
Posted: Wed Sep 03, 2008 11:20 pm
by andyhoneycutt
I may be wrong but I believe all that your elsif will do is compare the stdin input to whatever is in the last piece of your @something array.
It looks like what you are doing is saying if the key exists (and the user is searching for it), do something. Otherwise if the key equals the last item in the array (which should never trigger, because the first if will trigger: it exists), do something else.
Are you trying to allow a user to search until all keys are found? If you're just trying to loop through all possible items in the array, a foreach should suffice.
-Andy
Re: A Perl beginner's array searcher
Posted: Wed Sep 03, 2008 11:39 pm
by devdavad
andyhoneycutt wrote:I may be wrong but I believe all that your elsif will do is compare the stdin input to whatever is in the last piece of your @something array.
It looks like what you are doing is saying if the key exists (and the user is searching for it), do something. Otherwise if the key equals the last item in the array (which should never trigger, because the first if will trigger: it exists), do something else.
Are you trying to allow a user to search until all keys are found? If you're just trying to loop through all possible items in the array, a foreach should suffice.
-Andy
Thanks. I'm trying to allow a user to search until all keys are found and having the stdin be a regex without /'s.
And I'm stupid for putting this in a PHP forum.
Re: A Perl beginner's array searcher
Posted: Wed Sep 03, 2008 11:43 pm
by andyhoneycutt
not stupid at all. maybe a little misguided for putting it under coding critique, however: this particular forum, i believe, is designated for people asking other people to tear apart their code, make suggestions for optimizations and whatnot.
as far as your code goes, my suggestion would be to pop off a key from the array (and it's value, of course) after each time a user finds the key; do this until there is no more array.
-Andy