Post not showing in Thread

This topic contains 5 replies, has 2 voices, and was last updated by  Curtis Smith 1 year, 11 months ago.

  • Author
    Posts
  • #31983

    Curtis Smith
    Participant

    Hey, the last post I submitted to (https://powershell.org/forums/topic/dynamically-build-group-names-with-a-hashtable-and-string-array/) is not showing up, and when I try to re-post it, I get the message "ERROR: Duplicate reply detected; it looks as though you've already said that!"

  • #31984

    Curtis Smith
    Participant

    Here is the content that should be posted:

    Thanks Rohn, The method of using a function to call itself definitely does work. I have tested your code since you updated the RegEx and all is good. What I like about using a stack or queue is that it is much more efficient. When having a function call itself, new variables and references have to be established each time the function is called that along with every required to initiate the function to begin with make it much slower comparatively. Here are some stats on the two methods.

    Function calling itself:
    Average : 2.2696 milliseconds per run with a 10,000 run sample

    Stack/Queue:
    Average : 0.0191541499999998 milliseconds per run with a 10,000 run sample

    I love working on problems like this. They help me stretch my imagination and allow me to see ingenious solutions submitted by others. I made a slight adjustment to resolve a low potential issue.

    $attributes=@{
                    division=@("US","Europe")
                    department=@("Information Technology","Human Resources","Accounting","Finance")
                    employeeType=@("Employee","Contractor")
                 }
    
    [System.Collections.Stack]$templates = @(
                                                "role.[division].[division].[department]"
                                            )
    
    While ($templates.Count) {
        $item = $templates.Pop()
        $item -match '\[.+?\]' | Out-Null
    #    $item
        $tag = $matches.Values -replace '[\[\]]'
        ForEach ($attrib in $attributes."$tag") {
            $newitem = $item -replace "\[$tag\]", "$attrib"
            If ($newitem -match '\[.+?\]') {
                $templates.Push($newitem)
            }
            Else {
                ($newitem -replace " ").ToLower()
            }
        }
    }
    

    Prior to the adjustment, if a tag were used more than once, it would get undesired results.

    Before the adjustment, "role.[division].[division].[department]" would produce:
    role.europe.europe.informationtechnology
    role.europe.europe.humanresources
    role.europe.europe.accounting
    role.europe.europe.finance
    role.europe.us.informationtechnology
    role.europe.us.humanresources
    role.europe.us.accounting
    role.europe.us.finance
    role.us.europe.informationtechnology
    role.us.europe.humanresources
    role.us.europe.accounting
    role.us.europe.finance
    role.us.us.informationtechnology
    role.us.us.humanresources
    role.us.us.accounting
    role.us.us.finance

    After the adjustment, "role.[division].[division].[department]" will produce:
    role.europe.europe.informationtechnology
    role.europe.europe.humanresources
    role.europe.europe.accounting
    role.europe.europe.finance
    role.us.us.informationtechnology
    role.us.us.humanresources
    role.us.us.accounting
    role.us.us.finance

  • #31985

    Curtis Smith
    Participant

    Interesting. I just tried posting the content of that post here as well so that you could see what was missing, but it is not showing up here either. There must be something in there WordPress does not like.

  • #31986

    Curtis Smith
    Participant

    It's going to be post-31984 that has an issue. In this thread. Not sure what the post number is in the original thread.

  • #31991

    Don Jones
    Keymaster

    It was tagged as spam. I've released it.

  • #32011

    Curtis Smith
    Participant

    Ah, thanks Don

You must be logged in to reply to this topic.