Cari di Perl 
    Perl User Manual
Daftar Isi
(Sebelumnya) Return the number of bytes in ...Find a character's numeri ... (Berikutnya)
Functions for SCALARs or strings

Convert a string to an octal number

Daftar Isi

  • oct EXPR

  • oct

    Interprets EXPR as an octal string and returns the correspondingvalue. (If EXPR happens to start off with 0x, interprets it as ahex string. If EXPR starts off with 0b, it is interpreted as abinary string. Leading whitespace is ignored in all three cases.)The following will handle decimal, binary, octal, and hex in standardPerl notation:

    1. $val = oct($val) if $val =~ /^0/;

    If EXPR is omitted, uses $_. To go the other way (produce a numberin octal), use sprintf() or printf():

    1. $dec_perms = (stat("filename"))[2] & 07777;
    2. $oct_perm_str = sprintf "%o", $perms;

    The oct() function is commonly used when a string such as 644 needsto be converted into a file mode, for example. Although Perl automatically converts strings into numbers as needed, this automaticconversion assumes base 10.

    Leading white space is ignored without warning, as too are any trailing non-digits, such as a decimal point (oct only handles non-negativeintegers, not negative integers or floating point).

 
Source : perldoc.perl.org - Official documentation for the Perl programming language
Site maintained by Jon Allen (JJ)     See the project page for more details
Documentation maintained by the Perl 5 Porters
(Sebelumnya) Return the number of bytes in ...Find a character's numeri ... (Berikutnya)