[Wellington-pm] program using <STDIN> giving error.

David Benton davidthebenton at gmail.com
Sun Aug 27 23:11:59 PDT 2006


Hi people i'm a some what inactive member of this list but am having a
problem and as I'm still just learing perl its pretty basic but I was
wondering if someone could help me out with this and tell me what the
problem is...


## Program giving the error
	#!/usr/bin/perl
	#hex2dec.plx
	use strict;
	use warnings;

	# Ask the user for a Hexadecimal number
	print "What is the Hexadecimal number you wish to convert to decimal?";
	my $hex = <STDIN>;

	# Print the number to be converted
	print "converting the hexadecimal number, ", $hex, "\n";

	# Convert given hexadecimal number to decimal
	my $dec = hex($hex);

	# Print the converted number
	print "That is, ", $dec, " in decimal.\n";

## Error Message perl gives when running the program

	What is the Hexadecimal number you wish to convert to decimal?30
	converting the hexadecimal number, 30

	Illegal hexadecimal digit '
	' ignored at hex2dec.plx line 14, <STDIN> line 1.
	That is, 48 in decimal.

-------------------------------------------------------------------------------------

## Program with '<STDIN>' replaced by '30'
	#!/usr/bin/perl
	#hex2dec.plx
	use strict;
	use warnings;

	# Ask the user for a Hexadecimal number
	print "What is the Hexadecimal number you wish to convert to decimal?\n";
	my $hex = 30;

	# Print the number to be converted
	print "converting the hexadecimal number, ", $hex, "\n";

	# Convert given hexadecimal number to decimal
	my $dec = hex($hex);

	# Print the converted number
	print "That is, ", $dec, " in decimal.\n";


## Output from Program run with '<STDIN>' replaced by '30'

	What is the Hexadecimal number you wish to convert to decimal?
	converting the hexadecimal number, 30
	That is, 48 in decimal.


If you could tell me whats wrong it would be appreciated.


More information about the Wellington-pm mailing list