#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    31
    Rep Power
    2

    How to print 0(zero)?


    Hi All,
    I am new to perl and I am stuck somewhere...

    if $val=0x0; (it is a hexadecimal value)
    then how to print that same value, with the base system as well(i.e. 0x0)...
    print "$val"; is not giving exactly the same output
    can you please help me???
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,923
    Rep Power
    1225
    See perldoc -f sprintf

    Comments on this post

    • bonny1989 agrees
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    828
    Rep Power
    496
    Why not simply:

    perl Code:
    print "0x$val";


    That will print: "0x0".

    Or, if if you want to make sure to print an hexadecimal value in all cases:

    perl Code:
    printf "0x%x", $val;

    Comments on this post

    • bonny1989 agrees
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    31
    Rep Power
    2
    Thank you again to both of you, Laurent_R and FishMonger.
    Both of you helped me a lot.
    May god bless you!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    828
    Rep Power
    496
    Originally Posted by bonny1989
    Thank you again to both of you, Laurent_R and FishMonger.
    Both of you helped me a lot.
    May god bless you!
    My pleasure to help you.

    My only hope: that your knowledge in Perl will improve to the level where you will be able to help others.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    31
    Rep Power
    2
    Originally Posted by Laurent_R
    My pleasure to help you.

    My only hope: that your knowledge in Perl will improve to the level where you will be able to help others.
    oh... with your help, i will try to reach upto your level!

IMN logo majestic logo threadwatch logo seochat tools logo