婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > PowerShell實現統計函數嵌套深度

PowerShell實現統計函數嵌套深度

熱門標簽:電話智能外呼系統誠信合作 金融電銷公司怎么辦理外呼系統 湖州電銷防封卡 安徽400電話辦理 雷霆電話機器人電話 真人和電話機器人對話 使用電話機器人電銷是否違法 什么渠道可以找外呼系統客戶 信陽話務外呼系統怎么收費

當你調用某個函數時,PowerShell會增加一次嵌套層次。當一個函數調用了另一個函數,或著腳本,也會增加嵌套層次。今天分享一個函數,它能告訴你的腳本嵌套的層次:

function Test-NestLevel
{
$i = 1
$ok = $true
do
{
try
{
$test = Get-Variable -Name Host -Scope $i
}
catch
{
$ok = $false
}
$i++
} While ($ok)
 
$i
}

當你調用的函數具有遞歸調用時,上面的函數非常有用,來看一個調用的示例:

function Test-Diving
{
param($Depth)
 
if ($Depth -gt 10) { return }
 
"Diving deeper to $Depth meters..."
 
$currentDepth = Test-NestLevel
"calculated depth: $currentDepth"
 
Test-Diving -depth ($Depth+1)
}
 
Test-Diving -depth 1
 


當你運行Test-Diving時,函數會調用自己10次。函數使用一個參數來控制嵌套層次,而Test-NestLevel負責返回確切的深度數。

注意這里有個區別:Test-NestLevel返回絕對的嵌套層次,參數會紀錄這個函數調用自己多少次。如果Test-Diving被嵌入到另外一個函數中,絕對深度和相對深度會不同。

 

PS C:\&; Test-Diving -Depth 1
diving deeper to 1 meters...
calculated depth: 1
diving deeper to 2 meters...
calculated depth: 2
diving deeper to 3 meters...
calculated depth: 3
diving deeper to 4 meters...
calculated depth: 4
diving deeper to 5 meters...
calculated depth: 5
diving deeper to 6 meters...
calculated depth: 6
diving deeper to 7 meters...
calculated depth: 7
diving deeper to 8 meters...
calculated depth: 8
diving deeper to 9 meters...
calculated depth: 9
diving deeper to 10 meters...
calculated depth: 10
 
PS C:\&;  { Test-Diving -Depth 1 }
diving deeper to 1 meters...
calculated depth: 2
diving deeper to 2 meters...
calculated depth: 3
diving deeper to 3 meters...
calculated depth: 4
diving deeper to 4 meters...
calculated depth: 5
diving deeper to 5 meters...
calculated depth: 6
diving deeper to 6 meters...
calculated depth: 7
diving deeper to 7 meters...
calculated depth: 8
diving deeper to 8 meters...
calculated depth: 9
diving deeper to 9 meters...
calculated depth: 10
diving deeper to 10 meters...
calculated depth: 11
 
PS C:\&;


Test-NestLevel總會返回從當前代碼的作用域到全局作用域的嵌套深度。

標簽:鶴崗 德州 六盤水 運城 湛江 山南 濟南 岳陽

巨人網絡通訊聲明:本文標題《PowerShell實現統計函數嵌套深度》,本文關鍵詞  PowerShell,實現,統計,函數,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《PowerShell實現統計函數嵌套深度》相關的同類信息!
  • 本頁收集關于PowerShell實現統計函數嵌套深度的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 盐津县| 竹溪县| 海南省| 姜堰市| 迭部县| 大理市| 磐石市| 梅州市| 缙云县| 沁源县| 兴化市| 柞水县| 铜鼓县| 河南省| 当涂县| 白沙| 滨海县| 张家界市| 兴海县| 平果县| 鄂托克前旗| 沭阳县| 泰宁县| 克什克腾旗| 惠水县| 玉林市| 卓资县| 政和县| 巩义市| 响水县| 朔州市| 黄山市| 寿光市| 江津市| 枝江市| 抚顺县| 犍为县| 丰台区| 高台县| 九台市| 天祝|