Based on the user input i.e. $release_num, I have to take a call on a particular action.
Its working in certain cases but fails in some other cases. Need help in refining the final solution.
Code:
my $release_num;
my $short_release_num = substr($release_num, 0, 4);
if (($short_release_num eq '20a0') or ($short_release_num eq '20a1') or ($short_release_num eq '20a2'))
{
print " Build is required \n";
}
else
{
print " Build is NOT required \n";
}
Probable values of user input $release_num are as follows:
$release_num = "20a1";
$release_num = "20a1a11";
$release_num = "20a10";
$release_num = "20a10a11";
$release_num = "20a11";
$release_num = "20a11a1";
While my code works for some of the specific cases (20a1
), but its not a generic solution as it fails for cases like 20a10a11
. Please suggest how the code can be improved.
For Example: If the input is 20a10 or 20a10a11, the output should be "Build is NOT required"
whereas I'm getting the output as "Build is required
".
Expected Result:
For following inputs we should get "Build is required":
$release_num = "20a0";
$release_num = "20a0a1";
$release_num = "20a1";
$release_num = "20a1a2";
$release_num = "20a2a11";
$release_num = "20a2a1";
For following inputs we should get "Build is NOT required":
$release_num = "20a10";
$release_num = "20a10a11";
$release_num = "20a11";
$release_num = "20a11a1";