6/6/2023 0 Comments Strukt creates![]() If the element type does not start with a '*', the accessor returns the element value (after assignment). Will perlguts if this is not an appropriate object reference. The accessor's argument, if any, is assigned to the element. The element is initialized to the result of calling The element's value must be a reference blessed to the named class or to '*%', a reference to the hash element is returned. If the element type is '%', the accessor returns the hash element value. With one or two arguments, the first argument is a key specifying oneĮlement of the hash the second argument, if present, is assigned to the The element is a hash, initialized to (). If the element type is a reference to the array element is returned. If the element type is the accessor returns the array element value. With one or two arguments, the first argument is an index specifying oneĮlement of the array the second argument, if present, is assigned to theĪrray element. With no argument, the accessor returns a reference to the element's whole Type is '*$', a reference to the element is returned.Īrray or element is an array, initialized to (). If the element type is '$', the value of the element (after assignment) is returned. The element is a scalar, and is initialized to undef. The accessor method provided by struct for an element depends on the declared type of the element. The four element types - scalar, array, hash, and class - are representedīy strings - '$', '%', and a class name - optionally preceded by a '*'. Will be defined as an accessor method unless a method by that name isĮxplicitly defined in the latter case, a warning is issued if the warning The class created by struct must not be a subclass of another class other than UNIVERSAL.Ī function named new must not be explicitly defined in a class created by struct.Įach name-type pair declares one element of the struct. The array-based forms will be somewhat faster and smaller the The third form assumes the current package name as the class name.Īn object of a class created by the first and third forms is based on anĪrray, whereas an object of a class created by the second form is based onĪ hash. The first and second forms explicitly identify the name of the class beingĬreated. The struct function has three forms of parameter-list. (See Example 2.)Įach element's type can be scalar, array, hash, or class. Overridden by declaring a sub of the same name in the package. The new class is given a constructor method, new, for creating struct objects.Įach element in the struct data has an accessor method, which is used toĪssign to the element and to fetch its value. ![]() Given a list of element names and types, and optionally a class name, struct creates a Perl 5 class that implements a ``struct-like'' data structure. Struct( CLASS_NAME => ) Ĭlass::Struct exports a single function, struct. Here is our local, out-dated (pre-5.6) version:Ĭlass::Struct - declare struct-like datatypes as Perl classes See the current Perl documentation for Class::Struct. On at 00:51 UTC ( # 1173= perlfunc: print w/replies, xml )
0 Comments
Leave a Reply. |