Guest User

Untitled

a guest
Jun 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. #!/bin/perl
  2.  
  3. ###############################################################################
  4. # Chapter 3
  5. # John T Skarbek
  6. # 06.04.2009
  7. ###############################################################################
  8.  
  9. print "\nWelcome to chapter 3 Arrays and lists and such.\n";
  10. print "\nQuestion 1. Input a string seperated by lines,";
  11. print "\nThen we print the input in reverse order.\n";
  12. print "\nI'm using the <STDIN>, so input as much as you want.";
  13. print "\nFor the sake of uncleanliness, type in strings only.";
  14. print "\nand for the sake of question two, use names.";
  15. print "\nThen hit Ctl+D\n\n";
  16.  
  17. # so here we input ridding of \n
  18. chomp (@user_input = <STDIN>);
  19.  
  20. # let's reverse the input
  21. @user_input = reverse @user_input;
  22.  
  23. # now we print out, i'm gonna do it line by line
  24. # this is done by taking each input in the array and printing the variable
  25. foreach $user_input (@user_input){
  26. print $user_input . "\t";
  27. }
  28.  
  29. # this will tell me how many itmes the user entered
  30. $amount_input = @user_input;
  31.  
  32. print "\nEnd of Question 1 moving on.";
  33.  
  34. print "\n\nQuestion 2. A list of names are hardcoded,";
  35. print "\nGrab numbers via input line by line to print out these names.";
  36. print "\nI've only got 5 names in the list so type 1,2,3,4, or 5.";
  37. print "\n1: bob, 2: john, 3: chris, 4: alex, 5: joe\n\n";
  38.  
  39. # Let's hardcode the names
  40. @list_of_names = qw/ bob john chris alex joe/;
  41.  
  42. # without checking, let's input some number ridding of newline
  43. chomp (@user_number_input = <STDIN>);
  44.  
  45. print "\n";
  46.  
  47. # for every number input into the array, we grab oneof them
  48. # then print the associated name
  49. foreach $user_number (@user_number_input){
  50. print @list_of_names[$user_number - 1] . "\t";
  51. }
  52.  
  53. print "\n";
  54. print "End of Question 2, moving on.";
  55. print "\n";
  56. print "Question 3. We are going to input some strings,\n";
  57. print "Then we are going to ASCIIetize them. So input only strings.\n";
  58.  
  59. chomp (@user_string_input = <STDIN>);
  60. print "\n";
  61.  
  62. print "Now we print what you wanted: ";
  63. print sort(@user_string_input);
  64. print "\n";
  65. print "To answer the question, the output puts it on one line.";
  66. print "\nI can of course change this behavoir all I want as shown:\n";
  67.  
  68. foreach $user_string_var (@user_string_input){
  69. print "\n" . $user_string_var;
  70. }
  71.  
  72. print "\nEnd of Chatper 3.\n\n\n";
  73.  
  74.  
  75. #EOP
  76. print "\n";
Add Comment
Please, Sign In to add comment