Xref:Perl/c fgets()

From CoderGuide

Jump to: navigation, search


Reading in a line of text in Perl similar to C's fgets

Reading in a line of text is very easy in Perl. You surround the file handle in angle brackets <> and....

$line=<STDIN>;
 
#now let's get rid of that pesky newline
 
chomp($line);
 
print "$line\n";
#we could also use this in a loop...
 
while(<STDIN>){
   #when used in this way, the line read is saved in $_
   print $_;
}## will continue until EOF is reached.
Personal tools