Topic variable: Difference between revisions

no edit summary
m (un-omit)
No edit summary
Line 241:
3 # Number
9 # -> print square</lang>
 
=={{header|PowerShell}}==
In PowerShell the "topic" variable is <code>$_</code>.
 
<code>$_</code> is a placeholder for each object in the pipeline. Any cmdlet or advanced function that accepts input from the pipeline may use this variable.
 
 
The most common use is in the <code>ForEach-Object</code> cmdlet:
<lang PowerShell>
65..67 | ForEach-Object {$_ * 2} # Multiply the numbers by 2
65..67 | ForEach-Object {[char]$_ } # ASCII values of the numbers
</lang>
{{Out}}
<pre>
130
132
134
A
B
C
</pre>
Using <code>Where-Object</code> to filter the odd numbers from an array:
<lang PowerShell>
65..67 | Where-Object {$_ % 2}
</lang>
{{Out}}
<pre>
65
67
</pre>
Using <code>Format-Wide</code> to force an array into columns:
<lang PowerShell>
65..70 | Format-Wide {$_} -Column 3 -Force
</lang>
{{Out}}
<pre>
65 66 67
68 69 70
</pre>
 
=={{header|Python}}==
308

edits