in reply to Simulating user defined data types

There isn't an anonymous hash per se and there are no user defined data types. There are references to data holders (scalar, hash, array).

So your sample code is just a hash reference. Nothing special. What you describe as "data type called record" is a hash reference in a variable named record. You could rewrite the code like this to help clarify-

my $hash_ref = record(100,1000,10); my %record = %$hash_ref; # De-reference/copy the hash. print $record{max};

I know this is just a snippet but you are using strict and warnings in all your code, right? :)

Replies are listed 'Best First'.
Re^2: Simulating user defined data types
by JadeNB (Chaplain) on Aug 07, 2009 at 21:51 UTC
    I am a bit confused by the statement “there isn't an anonymous hash per se”. Do you mean that the concept doesn't exist in Perl, or that it isn't evidenced in this code? Both seem false to me. (The docs explicitly call hashrefs created via { ... } anonymous hashes, and there's certainly one of those in the OP's code.) Do you just mean that it's not useful to think of anonymous hashes as different from hashrefs?

      Yeah, you've got it. I was wrong/sloppy.

      My fumbled point was that what is being used is a hash ref and whatever anonymity existed in its creation is irrelevant and only confusing. I'd only want to bring anonymity into the discussion if the code looked like this: record(100,1000,10)->{max}