Post not showing in Thread

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!”

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

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.

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.

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

Ah, thanks Don