You really need to clarify your definitions 'string' and 'octal' through some examples. Octal is always a 'string' representation of a number. Ie. It uses a string of ascii/unicode characters for the digit '0' to '7' to represent the actual number.
Assuming the input received by the Perl program looks something like this:
C:\test>perl -le" print $ARGV[ 0 ] " 0666
0666
Then all you need to do is tell Perl to iterprete the contents of that string as octal (intuatively using the oct built-in function), and Perl will take care of the rest for you:
C:\test>perl -le"my $n = oct( $ARGV[ 0 ] ); printf qq[decimal %d (as o
+ctal: %o)\n], $n, $n " 0666
decimal 438 (as octal: 666)
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.