Scripting Games, Beginner Event 6, Coffee Break

Read a file containing coffee orders for a bunch of offices and add up the total number of coffees of each type.

Lines in the order file corresponding to the office number ("Office 100" etc) are dropped from the pipeline, other entries from the file are split into coffee type and number and used to populate a hash table.  Line 6 displays the resulting hash table.

  1 $Orders=@{}
  2 Get-Content 'c:\scripts\coffee.txt'|?{!($_ -match '^Office')}|%{
  3 	$coffee, $number = $_.split()
  4 	$Orders[$coffee]+=[int]$number
  5 } 
  6 $Orders.psbase.keys|%{"$($_): $($Orders[$_])"}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s