in reply to Re: alphanumeric autoincrement?
in thread alphanumeric autoincrement?

You mean you can mimic a user deinfed type by using objects. Not actually create a "type". I see nothing that's the equivilant to typedef in perl. You could mimic similar things with an array or a sub, without the expense of OO, but it's still not a user defined "type".

Replies are listed 'Best First'.
Re3: alphanumeric autoincrement?
by dragonchild (Archbishop) on Aug 16, 2001 at 16:57 UTC
    Here's the thing - there is no such thing as a "type" in Perl to begin with. (Well, not till Perl6, and even then, not really.) Whenever you do $foo++, the interpreter is converting $foo to an integer, whether it was a string or a float before, then incrementing it. This can lead to interesting behavior. For example, if you do:
    my $foo = "abc"; $foo++; print "$foo\n"; ---- abd my $foo = 1.1; $foo++; print "$foo\n"; ---- 2.1
    Neither of those behaviors, while perfectly logical, have any correspondence to C or Pascal or Java. The only thing the Perl compiler checks is what kind of variable you are working with, not what type.

    So, you are only ever working with an int, for example, through programmer choice. So, you're only ever working with a user-defined type by programmer choice. The compiler isn't going to enforce anything for you with regard to type. (Well, it's not exactly anything, but close enough for government work.)

    ------
    /me wants to be the brightest bulb in the chandelier!

    Vote paco for President!

      Whenever you do $foo++, the interpreter is converting $foo to an integer, whether it was a string or a float before, then incrementing it.

      Sorry to disagree, but Perl won't do this.

      How do you convert a string like 'perlhacker' to an integer?
      But Perl is able to increment 'perlhacker' to 'perlhackes', this is some magic built into the increment operator.