進制轉換以及字符串轉整數
Author: kbe@www.smth.org
Converting?Between?Octal?and?Hexadecimal
# -----------------------------
$number ? = ? hex ( $hexadecimal );????????? # ?hexadecimal
$number ? = ? oct ( $octal );??????????????? # ?octal
#-----------------------------
print ? " Gimme?a?number?in?decimal,?octal,?or?hex:? " ;
$num ? = ? < STDIN > ;
chomp ? $num ;
exit ? unless ? defined ? $num ;
$num ? = ? oct ( $num )? if ? $num ? =~ ? /^ 0 / ;? # ?does?both?oct?and?hex
printf ? " %d?%x?%o\n " , ? $num , ? $num , ? $num ;
# -----------------------------
print ? " Enter?file?permission?in?octal:? " ;
$permissions ? = ? < STDIN > ;
die ? " Exiting?
\n
"
?
unless
?
defined
?
$permissions
;
chomp ? $permissions ;
$permissions ? = ? oct ( $permissions );??? # ?permissions?always?octal
print ? " The?decimal?value?is?$permissions\n " ;
# -----------------------------
# -----------------------------
$number ? = ? hex ( $hexadecimal );????????? # ?hexadecimal
$number ? = ? oct ( $octal );??????????????? # ?octal
#-----------------------------
print ? " Gimme?a?number?in?decimal,?octal,?or?hex:? " ;
$num ? = ? < STDIN > ;
chomp ? $num ;
exit ? unless ? defined ? $num ;
$num ? = ? oct ( $num )? if ? $num ? =~ ? /^ 0 / ;? # ?does?both?oct?and?hex
printf ? " %d?%x?%o\n " , ? $num , ? $num , ? $num ;
# -----------------------------
print ? " Enter?file?permission?in?octal:? " ;
$permissions ? = ? < STDIN > ;
die ? " Exiting?

chomp ? $permissions ;
$permissions ? = ? oct ( $permissions );??? # ?permissions?always?octal
print ? " The?decimal?value?is?$permissions\n " ;
# -----------------------------
posted on 2006-03-17 23:31 weidagang2046 閱讀(742) 評論(0) 編輯 收藏 所屬分類: Perl