Illegal hex digit

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Apr 2009
Posts: 8
Reputation: sprok is an unknown quantity at this point 
Solved Threads: 0
sprok sprok is offline Offline
Newbie Poster

Illegal hex digit

 
0
  #1
Apr 19th, 2009
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!

---
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. my $decVal;
  7.  
  8. print "Please enter a hexadecimal value to be converted to decimal: ";
  9. $decVal = <STDIN>;
  10.  
  11. 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??
Last edited by sprok; Apr 19th, 2009 at 10:10 am. Reason: typo
Do I really have to sign here? Is it ok if I'll use my right hand, instead?!
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: Illegal hex digit

 
1
  #2
Apr 19th, 2009
  1. $decVal = <STDIN>;
  2. chomp($decVal);#<--- you need this
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 8
Reputation: sprok is an unknown quantity at this point 
Solved Threads: 0
sprok sprok is offline Offline
Newbie Poster

Re: Illegal hex digit

 
0
  #3
Apr 20th, 2009
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!

Originally Posted by KevinADC View Post
  1. $decVal = <STDIN>;
  2. chomp($decVal);#<--- you need this
Do I really have to sign here? Is it ok if I'll use my right hand, instead?!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC