Ok, the only data types in Perl are scalars, arrays and hashes from what I understand, but it is possible to simulate a user-defined data type using an anonymous hash. I don't think I have understood this concept in its entirety...

my resources are so limited. With resources I mean examples, so I am a bit shaky when it comes to holding a grip over simulating user-defined data types.

The code I have is presented underneath but I think I don't fully understand what a user-defined-data type is in terms of (why would it be there if the arrays, hashes, scalars and Perl overall have an intelligence capability) due to the concise nature of the code.

this code creates a data type called record that holds a value, its minimum possible and its maximum possible, I understood the mechanism of its working including the return of the anonymous hash and its reference thereof, but the concept is what I lack, so can a generous wiser monk make me understand why data types present themselves and what causes they do serve and how to get better at coming up with them.

sub record{ ($value, $max, $min)=@_; if($value>=$min && $value<=$max){ return{ #returning an anonymous ha +sh value=>$value, max =>$max, min =>$min, }; }else{ return; } } $myrecord=record(100,1000,10); print $myrecord->{max};
Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind

In reply to Simulating user defined data types by biohisham

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.