A Perl beginner's array searcher
Moderator: General Moderators
A Perl beginner's array searcher
delete this account
Last edited by devdavad on Sat Jul 11, 2009 11:08 pm, edited 1 time in total.
- andyhoneycutt
- Forum Contributor
- Posts: 468
- Joined: Wed Aug 27, 2008 10:02 am
- Location: Idaho Falls
Re: A Perl beginner's array searcher
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
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
Thanks. I'm trying to allow a user to search until all keys are found and having the stdin be a regex without /'s.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
And I'm stupid for putting this in a PHP forum.
- andyhoneycutt
- Forum Contributor
- Posts: 468
- Joined: Wed Aug 27, 2008 10:02 am
- Location: Idaho Falls
Re: A Perl beginner's array searcher
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
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