943,640 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Marked Solved
  • Views: 2012
  • Perl RSS
Apr 19th, 2009
0

Illegal hex digit

Expand Post »
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!

---
perl Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sprok is offline Offline
8 posts
since Apr 2009
Apr 19th, 2009
1

Re: Illegal hex digit

Perl Syntax (Toggle Plain Text)
  1. $decVal = <STDIN>;
  2. chomp($decVal);#<--- you need this
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Apr 20th, 2009
0

Re: Illegal hex digit

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!

Click to Expand / Collapse  Quote originally posted by KevinADC ...
Perl Syntax (Toggle Plain Text)
  1. $decVal = <STDIN>;
  2. chomp($decVal);#<--- you need this
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sprok is offline Offline
8 posts
since Apr 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC