Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Creating a unique variable type

by sundialsvc4 (Monsignor)
on Mar 25, 2013 at 12:57 UTC ( #1025289=note: print w/ replies, xml ) Need Help??


in reply to Creating a unique variable type

Perl is not a “strongly typed” language.   You cannot now say my $foo : integer;


Comment on Re: Creating a unique variable type
Re^2: Creating a unique variable type
by tfredett (Sexton) on Mar 25, 2013 at 20:28 UTC
    I understand that, I was primarily using the int and boolean as an example, I understand they both would be considered scalars until I assign them some value. The main point I was trying to get across was how I could get both those data types into one unit, in this case an object. The usefulness of this, for my particular case, is quite useful for the application I have desired for it. It should make the data easier to manage.
Re^2: Creating a unique variable type
by Athanasius (Monsignor) on Mar 26, 2013 at 08:23 UTC
    Perl is not a “strongly typed” language.

    True for some definitions of “strongly typed“ (see Strong_typing), but in this context I think it’s clearer if we describe Perl as dynamically typed, in contrast to languages like C which are statically typed. With static typing, a variable’s type is known at compile time; with dynamic typing, a (scalar) variable’s data type is determined at runtime, and may change as the script executes — $foo may hold a string, then an integer, then a reference, ...

    You cannot now say my $foo : integer;

    Well, not in core Perl, no. But if you have objects, you’ll probably be using an object system (and if not, please see the picture on Your Mother’s home page!), and in an object system like Moose you can certainly specify that $foo is an Int. Here is one way to approach the OP’s task using Moose:

    But this is still dynamic typing: if a type mismatch occurs, it is a runtime error which results.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      There is, indeed, not a single phrase in programming vernacular that has but one unambiguous meaning ... except maybe “crash.”

Re^2: Creating a unique variable type
by LanX (Canon) on Mar 26, 2013 at 23:09 UTC
    > You cannot now say my $foo : integer;

    O RLY?

    see attributes for enabling

    my $foo :integer;

    and the parser also allows "typing"

    DB<105> {package Int} DB<106> my Int $x => undef

    ... though w/o much benefit.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2014-07-22 18:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (125 votes), past polls