2011-01-18 3 views

답변

3

업데이트 이 작업을 수행하는 가장 좋은 방법은 대해서 typeof() 연산자입니다. 이것은 해답 이후 새로운 것이지만, 변수의 초기 해석과 함께 해답에 열거 된 오래된 방법은 더 이상 작동하지 않습니다.

데이터를 검사하는 또 다른 유용한 연산자는 ISNULL()

myHash.typeof() => "hash" 
myArray.typeof() => "array" 
... 
2

내가 데이터 구조의 유형을 감지하는 방법을 알아 낸 유일한 방법은 결과 있는지 확인하기 위해 문자열로 강요하고 확인하는 것입니다 포인터 문자열에 'array'또는 'hash'라는 단어가 포함되어 있습니다.

'하나 라이너'

myHashIsHash = "#{myHash}".match(re/hash/gi); 

myHashIsHash 행동의 개념을

ruleset a60x547 { 
    meta { 
    name "detect-array-or-hash" 
    description << 
     detect-array-or-hash 
    >> 
    author "Mike Grace" 
    logging on 
    } 

    global { 
    myHash = { 
     "asking":"Mike Farmer", 
     "question":"detect type" 
    }; 
    myArray = [0,1,2,3]; 
    } 

    rule detect_types { 
    select when pageview ".*" 
    pre { 
     myHashIsArray = "#{myHash}".match(re/array/gi); 
     myHashIsHash = "#{myHash}".match(re/hash/gi); 
     myArrayIsArray = "#{myArray}".match(re/array/gi); 
     myArrayIsHash = "#{myArray}".match(re/hash/gi); 

     hashAsString = "#{myHash}"; 
     arrayAsString = "#{myArray}"; 
    } 
    { 
     notify("hash as string",hashAsString) with sticky = true; 
     notify("array as string",arrayAsString) with sticky = true; 

     notify("hash is array",myHashIsArray) with sticky = true; 
     notify("hash is hash",myHashIsHash) with sticky = true; 
     notify("array is array",myArrayIsArray) with sticky = true; 
     notify("array is hash",myArrayIsHash) with sticky = true; 
    } 
    } 
} 

예제 응용 프로그램을 보여 내장/1

예제 응용 프로그램 사실이 될 것이다!

alt text

+0

이 최고입니다! 고맙습니다. 이것에 하나의 장애가 있습니다. 변수가 문자열이고 해당 문자열의 내용이 'ARRAY ...'또는 'HASH ...'인 경우 안정적으로 작동하지 않습니다. 변수가 문자열인지 감지하는 방법이 있는지 확인합니다. –

관련 문제