By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,279 Members | 1,629 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,279 IT Pros & Developers. It's quick & easy.

Perl Noob Question.

P: 5
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. use strict;
  3. print "Do you want a hex or octal \n";
  4. my $hoo = <STDIN>;
  5. chomp($hoo);
  7. if ($hoo = hex) {
  8. print "Please Type a Hex Number \n";
  9. my $A = <STDIN>;
  10. chomp($A);
  11. print "\n";
  12. print hex("$A")," <--- That is your Octal Number";
  13. }
  14. else {
  15. print "Please Type a Octal Number\n";
  16. my $AA = <STDIN>;
  17. chomp($AA);
  18. print "\n";
  19. print oct("$AA")," <--- That is your Octal Number";
  20. }

This is the error I get.

Do you want a hex or octal
Use of uninitialized value in hex at ./hex line 7, <STDIN> line 1.
Please Type a Octal Number

Illegal octal digit '9' ignored at ./hex line 19, <STDIN> line 2.
0 <--- That is your Octal Number
Feb 1 '08 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 971
With this line are you wanting to check to make sure that $hoo equals the string 'hex'?
Expand|Select|Wrap|Line Numbers
  1. if ($hoo = hex) 
If so, then you need to change it. Here are a couple of examples how that can be done.

Expand|Select|Wrap|Line Numbers
  1. if ($hoo eq 'hex') 
  2. # or
  3. if ($hoo =~ /^hex$/)
Feb 1 '08 #2

P: 5
Thank you much Kevin. I think I will be on these forums to get more into PERL.
Once again thank you.
Feb 1 '08 #3

Expert 100+
P: 971
Change your line of code to the following and see that gets rid of your error and achieves what you want.

Expand|Select|Wrap|Line Numbers
  1. print sprintf("%o",$AA), " <--- That is your Octal Number";
Thank you much Kevin. I think I will be on these forums to get more into PERL.
Once again thank you.
You are welcome. When posting code samples here please use the [CODE][/CODE] tags.

Thank You and Welcome to TSDN!

Feb 1 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.