Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Given When Syntax

by Marshall (Canon)
on Mar 16, 2014 at 15:03 UTC ( #1078519=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1078519]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2022-08-10 12:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?