Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: octal number mysteriously changes after pass to subroutine

by LanX (Saint)
on Feb 02, 2023 at 00:55 UTC ( [id://11150082]=note: print w/replies, xml ) Need Help??


in reply to Re^2: octal number mysteriously changes after pass to subroutine
in thread octal number mysteriously changes after pass to subroutine

There are fundamental things in Perl, which might be confusing here

  1. a scalar variable can be a number or a string (or a reference ...)
  2. There are various literal notations in code
  3. literals like "txt" , 'txt' , q(txt) , ... will produce the same string txt
  4. literals like 016 , 0xE , 14 will produce the same number (well integer) 14
  5. a string might look like a literal notation of a number like "016" , but literal notation inside strings will not be interpreted
  6. an implicit string to number conversion will always be decimal, hence "016" + 3  == 19 not 17
  7. if you want another base, you need to convert the string explicitly by yourself
  8. one (dangerous) way is eval("016") == 14

I hope it's clearer now.

Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11150082]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-25 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found