Scalars aren't necessarily one thing or another. There's no place to declare a scalar
variable to be of type "string", type "number", type "reference", or anything else.
Because of the automatic conversion of scalars, operations that return scalars don't need
to care (and in fact, cannot care) whether their caller is looking for a string, a num-
ber, or a reference. Perl is a contextually polymorphic language whose scalars can be
strings, numbers, or references (which includes objects). Although strings and numbers
are considered pretty much the same thing for nearly all purposes, references are
strongly-typed, uncastable pointers with builtin reference-counting and destructor invo-
cation.
Igor 'izut' Sutton
your code, your rules.
| [reply] |
If you _really_ need to force some type, you can tie the variable and check stored scalar against regexp, or you can write own xs module with required behavior. See perltie, perlxs, perlguts.
Nothing very easy (excluding tied variables), do you really need it? Perhaps some regexp check on input can satisfy your criteria... | [reply] |
This depends largely on what you are actually trying to accomplish. You could use Attribute::Types to simulate type-checking, but there's a good chance you don't actually need strong typing.
You could also create the behavior you want using overload and creating appropriate modules from which you can instantiate objects. You might also be looking for integer math. Or, if you're doing input validation, type casting, or something similar, you could use Data::Types.
So, what specifically are you aiming to accomplish?
| [reply] |
I needed this feature for input validation, which my tool would take from commandline arguments. I had plans to parse arguments through regex, but it seems I can use Attribute::Types and Data::Types for it
Thanks to everyone for the help.
| [reply] |
| [reply] [d/l] |