#!/usr/bin/perl
#####
#####<1>
#####@@@get a line from keyboard, like shell read var
print "What is your name? ";
$name=<STDIN>;
print "What is your father's name? ";
$paname=<>;
print "Hello respected one, $paname";
#####result
#What is your name? Stack
#What is your father's name? Tony
#Hello respected one, Tony


#####
#####<2>
#####@@@Getting rid of trailing newline. Use chomp instead of chop.
#####if there is only one char, it wouldn't be cutted.
print "\n###chomp and chop functin for perl beginning!!!!\n";
print "Hello there, and what is your name? \n";
chop($name=<STDIN>);
print "$name has been chopped a \\n char. \n";
chop($name);
print "$name has been chopped again. \n";
print "What is your age? \n";
chomp($age=<STDIN>);
print "$age has been chomped a \\n char. \n";
chomp($age);
print "$age didn't chomped again.\n";
#####result:
####chomp and chop functin for perl beginning!!!!
#Hello there, and what is your name?
#mywords
#mywords has been chopped a \n char.
#myword has been chopped again.
#What is your age?
#mywords
#mywords has been chomped a \n char.
#mywords didn't chomped again.


#####
#####<3>
#####@@@Reading input in a requested number of bytes
print "\n###read syntax beginning !!!\n";
print "Describe your favorite food in 10 bytes or less.\n";
print "If you type less than 7 characters, press Ctrl-d on a line by itself.\n";
$number=read(STDIN,$inputvar,7);
print "You just typed: $inputvar \n";
print "The number of bytes read was $number \n";
#####result:
####read syntax beginning !!!
#Describe your favorite food in 10 bytes or less.
#If you type less than 7 characters, press Ctrl-d on a line by itself.
#12345678
#You just typed: 1234567
#The number of bytes read was 7


#####
#####<4>
#####@@@function getc
print "Getting only one character of input!!! \n";
print "Answer y or n  \n";
$answer=getc;
$restofit=<>;
print "The getc function get the char is: $answer \n";
print "The characters left in the input buffer were:
$restofit \n";
#####result:
#Getting only one character of input!!!
#Answer y or n 
#y12345678redundancy
#The getc function get the char is: y
#The characters left in the input buffer were:
#12345678redundancy


#####
#####<5>
#####@@@Assigning input to an array
print "\n###Assigning input to an array beginning!!!!\n";
print "Tell me everthing about yourself. \n";
@all=<STDIN>;
print "your input are displayed: \n@all";
print "The number of elements in the array are: ", $#all + 1, " \n";
print "The first element of the array is : $all[0]";
#####result:
####Assigning input to an array beginning!!!!
#Tell me everthing about yourself.
#first x
#second x
#thrid x
#fourth x
#your input are displayed:
#first x
# second x
#  thrid x
#   fourth x
#   The number of elements in the array are: 4
#   The first element of the array is : first x

#####
#####<6>
#####@@@assign input to a hash
print "\n###Assign input to a hash beginning!!!!\n";
print "What is the name of course 101?\n";
$course_number=101;
chomp ($course{$course_number}=<STDIN>);
print %course, "\n";
print "print the values of key(101) is: $course{101}", "\n";
#####result
####Assign input to a hash beginning!!!!
#What is the name of course 101?
#xx
#101xx
#print the values of key(101) is: xx


#####
#####<7>
#####@@@chop(LIST) and chomp(LIST) for array.
print "\n###chop(LIST) and chomp(LIST) for array beginning!!!\n";
@line=("red","green","orange");
chop(@line);  #Chops the last character off each string in the list;
print "\n@line";
@line=("red","green","orange");
chomp(@line); #Chomps the newline off each string in the list
print "\n@line\n";
#####result:
#re gree orang
#red green orange