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:
display ascii

 



adiolord
Novice

Feb 9, 2009, 3:01 PM

Post #1 of 9 (1358 views)
display ascii Can't Post

Basically I have to prompt the user for a case insensitive selection of either (a, A, b, B) string value, if they choose a/A, display all 255 ASCII characters in an array in ascending order, b/B, descending order.

If neither a/A/b/B are chosen report an invalid selection and loop until successful. I am brand new to Perl and would love some help getting this script off the ground.

Thankyou!


KevinR
Veteran


Feb 9, 2009, 7:23 PM

Post #2 of 9 (1352 views)
Re: [adiolord] display ascii [In reply to] Can't Post


Code
use strict; 
use warnings;

print "Enter a/A/b/B: ";
my $in = <STDIN>;
chomp $in;
unless ($in =~ /^[ab]$/i) {
print "Ivalid entry\n";
exit;
}
#here you display the ascii stuff

-------------------------------------------------


KevinR
Veteran


Feb 9, 2009, 8:08 PM

Post #3 of 9 (1343 views)
Re: [adiolord] display ascii [In reply to] Can't Post

Why did you remove your code?
-------------------------------------------------


adiolord
Novice

Feb 9, 2009, 8:12 PM

Post #4 of 9 (1342 views)
Post deleted by adiolord [In reply to]

 


adiolord
Novice

Feb 9, 2009, 8:14 PM

Post #5 of 9 (1341 views)
Re: [adiolord] display ascii [In reply to] Can't Post

I'm basically throwing rocks at everything I see untill I hit something I can kill and eat... must look like a horid mess eh


KevinR
Veteran


Feb 9, 2009, 8:59 PM

Post #6 of 9 (1338 views)
Re: [adiolord] display ascii [In reply to] Can't Post


Quote
I posted it, and saw a huge mistake lol


Thats cool, we love to point out errors. Wink
-------------------------------------------------


KevinR
Veteran


Feb 9, 2009, 9:02 PM

Post #7 of 9 (1336 views)
Re: [adiolord] display ascii [In reply to] Can't Post

Error here:


Code
for ( $i;$i <= 255; $i++ ) {  
$ascii[$i] = chr($i) ;
}


Should be:


Code
for ( $i=0;$i <= 255; $i++ ) {  
$ascii[$i] = chr($i) ;


I see you set $i at the beginning of the script but you have to initialize it inside the loop condition and assign it a value.
}
-------------------------------------------------


adiolord
Novice

Feb 9, 2009, 10:05 PM

Post #8 of 9 (1331 views)
Re: [KevinR] display ascii [In reply to] Can't Post

It works though assigned at the beginning, and also, would that not slow down the loop? or does it only work with what is after the set variable being $i=0?


FishMonger
Veteran / Moderator

Feb 9, 2009, 11:00 PM

Post #9 of 9 (1330 views)
Re: [adiolord] display ascii [In reply to] Can't Post

Why do you keep deleting your code? Is that so your instructor doesn't know that you're getting help from others?

for ( $i=0;$i <= 255; $i++ ) {

is better written as

for my $i ( 0..255 ) {

There are a number of issues I could point out, but your instructor might accept this homework as is.

 
 


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

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