[Wellington-pm] program using <STDIN> giving error.
Douglas Bagnall
douglas at paradise.net.nz
Sun Aug 27 23:54:00 PDT 2006
David Benton wrote:
> my $hex = <STDIN>;
>
> # Print the number to be converted
> print "converting the hexadecimal number, ", $hex, "\n";
>
your $hex will end with a line ending character. You'd see this more
clearly if there were printable characters after it in the print; eg:
print "converting the hexadecimal number '$hex'\n";
Formatting debug messages like this helps to show empty or padded values.
Anyway, one answer is to do away with whitespace like this:
my $hex = <STDIN>;
$hex =~ s/\s//g;
but there are no doubt more perlish ways using functions beginning with
'ch'.
douglas
More information about the Wellington-pm
mailing list