def tricky_split(line, delim):
    """tricky_split(line, delim) - split line by delimiter delim, but ignoring
       delimiters found inside ()'s, []'s, {}'s, '''s and ""'s.

       eg: tricky_split("email(root,'hi there'),system('echo hi, mum')", ',')
       would return: [ "email(root,'hi there')", "system('echo hi, mum')" ]
    """
    parenCnt = 0
    curlyCnt = 0
    squareCnt = 0
    doubleqCnt = 0
    quoteCnt = 0
    list = []
    current = ''
    for c in line:
        if c == '(':
            parenCnt = parenCnt + 1
        elif c == ')':
            parenCnt = parenCnt - 1
        elif c == '{':
            curlyCnt = curlyCnt + 1
        elif c == '}':
            curlyCnt = curlyCnt - 1
        elif c == '[':
            squareCnt = squareCnt + 1
        elif c == ']':
            squareCnt = squareCnt - 1
        elif c == '"':
            doubleqCnt = 1 - doubleqCnt
        elif c == "'":
            quoteCnt = 1 - quoteCnt
        elif c == delim:
            if (parenCnt == 0 and curlyCnt == 0 and squareCnt == 0 and 
                doubleqCnt == 0 and quoteCnt == 0):
                list.append(current)
                current = ''
                continue
        current = current + c
    if len(current) > 0:
        list.append(current)
    return list
