http://qs321.pair.com?node_id=1078519


in reply to Re^2: Given When Syntax
in thread Given When Syntax

Try this:
sub test2 { my ($var2) = shift; # Perl can implement the if/else idea very code efficiently. return ("One") if ($var2 =~ /^1\./ ); return ("Two") if ($var2 =~ /^2\./ ); return ("Three") if ($var2 =~ /^3\./ ); return ("UNKOWN"); } print test2 ("1.00.000"), "\n"; print test2 ("11.00.000"), "\n"; print test2 ("3.abc"), "\n"; __END__ prints: One UNKOWN Three
Update:
Well I think we both know that this is a simple example.
The regex'es aren't complicated. Just to demo the idea.

Replies are listed 'Best First'.
Re^4: Given When Syntax
by Deep_Plaid (Acolyte) on Mar 16, 2014 at 16:19 UTC

    Thanks, Marshal. That did the trick. I was an idiot for not seeing the subroutine was not identified in your code snippet as it was in my example. Thanks again for your time and patience.