Hello,

I have this code of converting hexadecimal value to decimal but getting a warning at compilation. I'm starting to learn Perl and this one really makes me - almost - crazy! :)

---

#!/usr/bin/perl

use strict;
use warnings;

my $decVal;

print "Please enter a hexadecimal value to be converted to decimal: ";
$decVal = <STDIN>;

print "The value in decimal is: ", hex($decVal), "\n";

---
When I try to compile it:

Sproky: $ perl hexoct2dec2.plx
Please enter a hexadecimal value to be converted to decimal: 30
Illegal hexadecimal digit '
' ignored at hex2dec2.plx line 11, <STDIN> line 1.
The value in decimal is: 48

Anyone to shed some light please??

Recommended Answers

All 2 Replies

$decVal = <STDIN>;
chomp($decVal);#<--- you need this

Worked like a charm! Thanks.

I asked a colleague (when I posted this, I'm at home, so never had the chance) I was told that it removes the "extra" character "\n" as I press Enter. Noted!

$decVal = <STDIN>;
chomp($decVal);#<--- you need this
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.