How can I validate enum types as Perl subroutine arguments? -


Closing, how can I check the dynamic type (or if it is capable of using strictly typing styptic type) The true type of suburban logic is happening?

  package phone :: type; Continuous {Home = & gt; 'Home', Task = & gt; 'work', }; Package head; Sub Fun {my ($ my_phone_type_enum) = @_; # How to check my_phone_type_enum, either the phone :: type-> home or phone :: type- & gt; WORK or ... but not 'dog' or 'cat'? } HAPPY (Phone :: Type-> HOME); # Valid joke (phone :: type-> WORK); # Valid joke ('dog'); Compile # run-time or time  

Here's a way:

  #! / Usr / bin / perl package phone :: type; Strict use; Use warnings; Continuous {Home = & gt; 'Home', Task = & gt; 'work', }; Package head; Strict use; Use warnings; Sub Fun {my ($ phone_type) = @_; Phone :: Type-> ($ Phone_type) or die '' $ phone_type 'is not valid \ n ";} Funny (' home '); #private joke (' work '); # valid joke (' dog '); # Compile run-time or time __END__ c: \ floating> dfg 'DOG' is not valid  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -