convert “Yes” or “No” to boolean
I want to parse user values contained in .CSV file. I don't want my users to enter "Yes" or "No" but instead enter "True" or "False". In each case I want to convert to the equivalent boolean values: $true or $false . Ideally I would like a default value, so if there's misspelt "Yes or "No" I would return my default value: $true or $false . Hence, I wondered if there is a neat way of doing this other than if(){} else (){} One way is a switch statement: $bool = switch ($string) { 'yes' { $true } 'no' { $false } } Add a clause default if you want to handle values that are neither "yes" nor "no":