Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8883781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:53:57+00:00 2026-06-14T20:53:57+00:00

An it works — but is it a best practice? question. In Perl there’s

  • 0

An “it works — but is it a best practice?” question. In Perl there’s a compact way of keeping track of occurrences of, say, strings found within a file: store them in a hash table. For example:

$HashTable{'the string in question'}++;

Perl increments the value for key the string in question as many times as this is done. It ensures unique “hits” at the same time that it keeps track of occurrences. Just hacking around, I found I could do much the same with Powershell:

$HashTable['a']++ or even

$Hashtable.a++ (which kind of surprised me — or even)

$Hashtable."this is a key"++

Ok, so it works. But is there an approach in Powershell that’s considered a better practice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:53:58+00:00Added an answer on June 14, 2026 at 8:53 pm

    Your approach looks quite good, at least for PowerShell with its helpers for hashtables. Just keep in mind that hashtables defined as @{} are case insensitive. If you need a case sensitive hashtable then create it like New-Object System.Collections.Hashtable.

    Example:

    # case insensitive
    $hash = @{}
    $hash['a']++
    $hash['A']++
    $hash
    
    '------------------------'
    
    # case sensitive
    $hash = New-Object System.Collections.Hashtable
    $hash['a']++
    $hash['A']++
    $hash
    

    Output:

    Name                           Value
    ----                           -----
    a                              2
    ------------------------
    a                              1
    A                              1
    

    In C# using Dictionary<string, int> is probably a “better practice”. It is also possible in PowerShell but it unlikely makes things much “better” in PowerShell.

    A PowerShell-ish solution is probably use of Group-Object -NoElement. Is it a better approach or practice? I do not know. It depends on a few factors including preferences. Here is the example:

    'a', 'A', 'foo', 'foo' , 'bar' | Group-Object -NoElement
    

    Output:

    Count Name
    ----- ----
        2 a
        2 foo
        1 bar
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This works, but i would like to remove the redundancy. Is there a way
This works, but is it the proper way to do it??? I have a
Everything works, but this is just to know the correct practice/right approach/what makes sense
This works great at retrieving the php data for say 15 passes BUT when
works fine on the desktop with xampp but when i upload it to my
This works but for some reason the comma is missing. data gets inserted as
This works when I used a rectangle as the food but now I'm trying
works on safari/firefox/chrome/opera for mac + pc. But not for safari iPhone. error occurred
This works but I'm not sure why. In function capIn() , in my mind
This works (in firefox but not ie): document.getElementById(filename+'Likes').innerHTML=result; document.getElementById(filename+'Like').setAttribute('class','hideGalleryLike'); document.getElementById(filename+'Dislike').setAttribute('class','hideGalleryLike'); I thought the jquery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.