|Don't ask to ask, just ask|
Re^3: Relationship between chomp() operator and STDINby Random_Walk (Prior)
|on Apr 30, 2013 at 05:17 UTC||Need Help??|
Scalar variables don't need to have a trailing newline. Unlike C where a string is normaly terminated with a nul, in Perl the string data structure stores the length of the string.
What is happeneing with your code is this:
As you type STDIN picks up each character and displays it to the screen a,a,a,\n are all displayed in turn.
The \n causes the newline/cariage return on the screen and tells STDIN that a record is ready to hand off to your code.
Now youre code runs chomp on $name and removes any instances of the input line seperator from the end of your string. By default the input line seperator is "\n", but you can change it by altering the value of $/
finaly your code prints Thank you $name; # no newline in a $name anymore and exits. The OS gives you back a prompt.
If you read from a file containing aaa\n instead of STDIN the output of your code would be the same, but as you are not using the keyboard to enter the data you would miss the initial line of aaa\n being shown on the display
Pereant, qui ante nos nostra dixerunt!