Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Output Question

Status
Not open for further replies.

MikeCopeland

Programmer
May 21, 2007
91
US
I am just starting to learn Perl, and I have a simple question: why is the "!" (in the "Hello..." statement) appearing on a new line in the following program's execution?:

#!/usr/bin/perl
print "The Phantom Spitter was here.\n";
print "Enter your name: \n";
$myName = <STDIN>;
print "Hello, $myName!\n"; ## <--this line...
print "Finis...";
 
<STDIN> is capturing the enter/return key as a CR/CRLF combination.

Broken down, $myname might contain "Mike Copeland\n".

To prevent this, chomp() your input:
Code:
$myname = <STDIN>;
chomp($myname);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top