By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,834 Members | 2,234 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,834 IT Pros & Developers. It's quick & easy.

subroutine that searches an array for an item

P: 4
i need to make a subroutine that searches an array for an item . If it finds the item it should return the array index of the item, if it does not find then the return value should be -1.

if anyone could help me i would really appreciate it?

my $index=&find($item, @array);
if ($index>=0)
Mar 30 '10 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 100+
P: 589
Are you and jsos20 the same person, or just in the same class?

We are not going to do your homework, but we can give you some guidance.

Start by trying to write the sub yourself and when you get stuck, post your code and ask specific questions. Your post should include all warnings and error messages that your code produces.

Your script should include these 2 lines near the top.
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
BTW, your instructor is teaching you some very poor coding practices which tells me that (s)he doesn't know Perl very well.
Mar 30 '10 #2

P: 4
no not the same person at all, being honest it is homework but this is only a very small part of it,my program does have the use strict and that in it but i dont know how to ask questions in the perl program as i have only started perl in the last month, im terrible with subroutines and do learn from people who help if the explain the code,and i will help people when i am good enough to,and yes my lecturer just gives us stuff to do and does not really help as there is a lot in the class.
Mar 30 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.