Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Beginning Perl <STDIN>

Tags:

perl

This is a very simple and non-critical question. I have some programming background eons ago (starting with FORTRAN, that's how long ago) and am working on learning some basics of perl coding using Simon Cozen's Beginning Perl. Chapter 2 assignments include writing a simple program to interpret an integer entry (<STDIN>) and printing the decimal integer equal to the number. I have Windows 7. When the integer is entered, the program outputs the warning

 Illegal hexadecimal digit '
 ' ignored at [path] line [the line containing the print instruction], <STDIN> line 1

Then it does print the correct hex number.

The code is

$number = <STDIN>;
print hex($number), "\n";

When I change the program to output an octal I don't get the warning.

The warning says the illegal digit occurs at the print line even though it references the STDIN line. Does it have to do with the enter key? If so, why does the oct version of the same program not have a problem?

like image 950
Sheri McMahon Avatar asked Apr 22 '12 02:04

Sheri McMahon


1 Answers

The problem is that $number has the line terminator in it still; use chomp to remove it.

like image 172
geekosaur Avatar answered Oct 23 '22 19:10

geekosaur