infor.com
concierge
infor u
developer portal
documentation central
customer center
Posts
Categories
Groups
ERPs
CSD
FSM/HRT
LN
M3
Syteline/ CSI
Hubs
Developer
Healthcare
Hospitality
Public Sector
Onboarding
Release Center
CloudSuites
Aerospace & Defense (LN)
Automotive (LN)
Chemicals (M3)
Corporate (FSM/HRT)
Distribution (Sx.e/CSD)
Distribution Enterprise (M3)
Engineering & Construction (LN)
Fashion (M3)
Food & Beverage (M3)
Healthcare (FSM/HRT)
Industrial (Syteline/CSI)
Industrial Enterprise (LN)
Manufacturing (M3)
Public Sector (FSM/HRT)
Solutions
Supply Chain Management (SCM)
Human Capital Management (HCM)
Events
Groups
User Groups
Your Groups
About
Email Community Support
Infor News
Migrated Forums
Home
Clovertech
Clovertech Archive
Read Only Archives
Cloverleaf
General
Switch Command using variable for regexp
Keith McLeod
I am trying to use the switch command with the regexp switches. It works when I explicitly use the pattern for the case. I would like to make each pattern a variable. This is where I run into trouble. It doesn't work. I read somewhere that the curly braces surrounding the body of the switch statement needs to be removed. Not successful there either.
If the variable should match with style_1 it drops to default. Any suggestions?
Here is a sample:
set style_1 {^[0-9]$}
foreach phone $List {
switch -regexp -- $phone {
$style_1 {
echo "Style 1 found"
}
^[0-9][0-9]$ {
echo "Style 2 found"
}
^[0-9][0-9][0-9]$ {
echo "Style 3 found"
}
^[0-9][0-9][0-9][0-9]$ {
echo "Style 4 found"
}
^[0-9][0-9][0-9][0-9][0-9]$ {
echo "Style 5 found"
}
default {
echo "Style default found"
}
}
}
Find more posts tagged with
Clovertech
Comments
Charlie Bursell
You can not evaluate a variable inside braces like this. You have to use a different style for the switch. Try this:
switch -regexp -- $phone
$style_1 {echo "Style 1 found"}
{^[0-9][0-9]$} {echo "Style 2 found"}
{^[0-9][0-9][0-9]$} {echo "Style 3 found"}
{^[0-9][0-9][0-9][0-9]$} { echo "Style 4 found"}
{^[0-9][0-9][0-9][0-9][0-9]$} {echo "Style 5 found"}
default {echo "Style default found} 8)
Keith McLeod
Thanks... I did figure it out. I knew it had to do with that. The spaces between each case, I believe was the other part as to why it did not work at first.....