CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Algorithm Help

 



arousek
Novice

Apr 13, 2010, 2:18 AM

Post #1 of 7 (820 views)
Algorithm Help Can't Post

Hi guys i need to design an algorithm that, using a loop, accept five names from user, store names in an array. the array must start out empty. Then allow user to continually (another loop) enter an integer representing the array location of one of the names, and display the matching name.

Do not accept integer values that cannot represent array locations/indexes/subscripts, with excpeption of special value 99 to end the lookup. Invalid array location apart from 99 should display invalid position please try again

Would someone show me how this would be done, i haven't done anything yet and new to creating array.


(This post was edited by arousek on Apr 13, 2010, 2:20 AM)


7stud
Enthusiast

Apr 13, 2010, 2:23 AM

Post #2 of 7 (816 views)
Re: [arousek] Algorithm Help [In reply to] Can't Post


Code
use strict; 
use warnings;
use 5.010;

my @names = ();

my $str = 'hello';

for my $number (1 .. 10) {
push @names, "$str $number";
}

say $names[0];
say '-' x 10;

for (@names) {
say;
}



--output:--
hello 1
----------
hello 1
hello 2
hello 3
hello 4
hello 5
hello 6
hello 7
hello 8
hello 9
hello 10



(This post was edited by 7stud on Apr 13, 2010, 2:26 AM)


arousek
Novice

Apr 13, 2010, 2:56 AM

Post #3 of 7 (810 views)
Re: [7stud] Algorithm Help [In reply to] Can't Post

Thanks the algorithm also needs to end at 99 and any invalid array should display invalid position please try again. Is there any way to make it more simple we are only learning simple perl programming Thanks for help


arousek
Novice

Apr 13, 2010, 3:00 AM

Post #4 of 7 (809 views)
Re: [arousek] Algorithm Help [In reply to] Can't Post

we are only using perl 5.8.4 more basic


7stud
Enthusiast

Apr 13, 2010, 3:30 AM

Post #5 of 7 (807 views)
Re: [arousek] Algorithm Help [In reply to] Can't Post

Substitute:

print xxx, "\n";

for:

say xxx;


arousek
Novice

Apr 13, 2010, 4:43 AM

Post #6 of 7 (803 views)
Re: [7stud] Algorithm Help [In reply to] Can't Post

The program needs to prompt user to enter a name how would i do that? Thanks for help


7stud
Enthusiast

Apr 13, 2010, 9:15 PM

Post #7 of 7 (790 views)
Re: [arousek] Algorithm Help [In reply to] Can't Post

...by reading some beginning perl tutorials.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives