Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/perl
- ###############################################################################
- # Chapter 3
- # John T Skarbek
- # 06.04.2009
- ###############################################################################
- print "\nWelcome to chapter 3 Arrays and lists and such.\n";
- print "\nQuestion 1. Input a string seperated by lines,";
- print "\nThen we print the input in reverse order.\n";
- print "\nI'm using the <STDIN>, so input as much as you want.";
- print "\nFor the sake of uncleanliness, type in strings only.";
- print "\nand for the sake of question two, use names.";
- print "\nThen hit Ctl+D\n\n";
- # so here we input ridding of \n
- chomp (@user_input = <STDIN>);
- # let's reverse the input
- @user_input = reverse @user_input;
- # now we print out, i'm gonna do it line by line
- # this is done by taking each input in the array and printing the variable
- foreach $user_input (@user_input){
- print $user_input . "\t";
- }
- # this will tell me how many itmes the user entered
- $amount_input = @user_input;
- print "\nEnd of Question 1 moving on.";
- print "\n\nQuestion 2. A list of names are hardcoded,";
- print "\nGrab numbers via input line by line to print out these names.";
- print "\nI've only got 5 names in the list so type 1,2,3,4, or 5.";
- print "\n1: bob, 2: john, 3: chris, 4: alex, 5: joe\n\n";
- # Let's hardcode the names
- @list_of_names = qw/ bob john chris alex joe/;
- # without checking, let's input some number ridding of newline
- chomp (@user_number_input = <STDIN>);
- print "\n";
- # for every number input into the array, we grab oneof them
- # then print the associated name
- foreach $user_number (@user_number_input){
- print @list_of_names[$user_number - 1] . "\t";
- }
- print "\n";
- print "End of Question 2, moving on.";
- print "\n";
- print "Question 3. We are going to input some strings,\n";
- print "Then we are going to ASCIIetize them. So input only strings.\n";
- chomp (@user_string_input = <STDIN>);
- print "\n";
- print "Now we print what you wanted: ";
- print sort(@user_string_input);
- print "\n";
- print "To answer the question, the output puts it on one line.";
- print "\nI can of course change this behavoir all I want as shown:\n";
- foreach $user_string_var (@user_string_input){
- print "\n" . $user_string_var;
- }
- print "\nEnd of Chatper 3.\n\n\n";
- #EOP
- print "\n";
Add Comment
Please, Sign In to add comment