# Trending December 2023 # Types Of Graphs With Examples # Suggested January 2024 # Top 15 Popular

You are reading the article Types Of Graphs With Examples updated in December 2023 on the website Achiashop.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested January 2024 Types Of Graphs With Examples

A graph is a non-linear data structure that consists of vertices and edges. The vertices contain the information or data, and the edges work as a link between pair of vertices.

Graphs can be of multiple types, depending on the position of the nodes and edges. Here’re some important types of Graphs:

Directed Graph

The edges of the Directed Graph contain arrows that mean the direction. The arrow determines where the edge is pointed to or ends.

Here’s an example of the Directed Graph.

Directed Graph

We can go from Node A to D.

However, we can’t go from node D to node A as the edge points from A to D.

As the Graph does not have weights, traveling from vertex A to D will cost the same as traveling from D to F.

Undirected Graph

Undirected Graph contains edges without pointers. It means we can travel vice versa between two vertices.

Here’s a simple example of the undirected Graph.

Undirected Graph

In the above Graph,

We can move from A to B

We can also move from B to A

Edges contain no directions.

It’s an example of an undirected graph having a finite number of vertices and edges with no weights.

Weighted Graph

Graph that contains weights or costs on the edges is called a weighted Graph. The numerical value generally represents the moving cost from one vertex to another vertex. Both Directed and Undirected Graph can have weights on their edges.

Here’s an example of a weighted graph (Directed).

Directed Graph with weight

A to B, there’s an edge, and the weight is 5, which means moving from A to B will cost us 5.

A point to B, but in this Graph, B has no direct edge over A. So, we can’t travel from B to A.

However, If we want to move from A to F, there are multiple paths. The paths are ADF, ABF. ADF will cost (10+11) or 21.

Here, the path ABF will cost (5+15) or 20. Here we’re adding the weight of each edge in the path.

Here’s an example of an Undirected Graph with weights:

Undirected Graph with weight

Here, the edge has weight but no direction. So, it means traveling from vertex A to D will cost 10 and vice versa.

Bi-Directional Graph

Bi-directional and undirected graphs have a common property. That is

Generally, the undirected Graph can have one edge between two vertexes.

For example:

Here, moving from A to D or D to A will cost 10.

In a Bi-Directional Graph, we can have two edges between two vertices.

Here’s an example:

Bi-Directional Graph

Traveling from A to D will cost us 17, but traveling from D to A will cost us 12. So, we can’t assign two different weights if it is an undirected graph.

Infinite Graph

The Graph will contain an infinite number of edges and nodes. If a graph is Infinite and it’s also a connected graph, then it will contain an infinite number of edges as well. Here, the extended edges mean that more edges might be connected to these nodes via edges.

Here’s an example of the infinite Graph:

Infinite Graph

Null Graph

Null Graph contains only nodes or vertices but with no edges. If given a Graph G = (V, E), where V is vertices and E is edges, it will be null if the number of edges E is zero.

Here’s an example of a Null Graph:

Null Graph

Trivial Graph

A graph data structure is considered trivial if only one vertex or node is present with no edges.

Here’s an example of a Trivial Graph:

Multi Graph

A graph is called a multigraph when multiple edges are present between two vertices, or the vertex has a loop. The term “Loop” in Graph Data Structure means an edge pointing to the same node or vertex. Multigraph can be directed or undirected.

Here’s an example of a Multi Graph:

There’re two edges from B to A. Moreover, vertex E has a self-loop. The above Graph is a directed graph with no weights on edges.

Complete Graph

A graph is complete if each vertex has directed or undirected edges with all other vertices.

Suppose there’s a total V number of vertices and each vertex has exactly V-1 edges. Then, this Graph will be called a Complete Graph. In this type of Graph, each vertex is connected to all other vertices via edges.

Here’s an example of a Complete Graph with five vertices:

You can see in the image the total number of nodes is five, and all the nodes have exactly four edges.

Connected Graph

A Graph is called a Connected graph if we start from a node or vertex and travel all the nodes from the starting node. For this, there should be at least one edge between each pair of nodes or vertices.

Here’s an example of a Connected Graph:

Here’s some explanation of the above Graph:

Assuming there’s no edge between C and F, we can’t travel from A to G. However, the edge C to F enables us to travel to any node from a given node.

A complete Graph is a Connected Graph because we can move from a node to any other node in the given Graph.

Cyclic Graph

A graph is said to be cyclic if there are one or more cycles present in the Graph.

Here’s an example of a Cyclic Graph:

Here, vertex A, B, and C form a cycle.

A graph can have multiple cycles inside it.

Directed Acyclic Graph (DAG)

A Graph is Called Directed Acyclic Graph or DAG if there’re no cycles inside a graph. DAG is important while doing the Topological Sort or finding the execution order. DAG is also important for creating scheduling systems or scanning dependency of resources etc. However, the above Graph above doesn’t contain any cycle inside.

Here’s a simple example of a Directed Acyclic Graph (DAG):

Cycle Graph

Cycle Graph is not the same as the cyclic Graph. In Cycle Graph, each node will have exactly two edges connected, meaning each node will have exactly two degrees.

Here’s an example of a Cycle Graph:

Bipartite Graph

These kinds of Graphs are special kinds of Graph where vertices are assigned to two sets.

Bipartite Graph must follow the rule:

Two sets of vertices should be distinct, which means all the vertices must be divided into two groups or sets.

Same set Vertices should not form any edges.

Euler Graph

A Graph Data Structure is said to be an Euler Graph if all the vertices have an even-numbered degree. The term degree of vertices means the number of edges pointing to or pointing out from a particular vertex.

Here’s an example of a Euler graph:

All the vertices have even degrees. Vertex A, D, E, and H have two degrees. Here, node C has four degrees, which is even.

Hamilton Graph

Hamilton Graph is a Connect Graph, where you can visit all the vertices from a given vertex without revisiting the same node or using the same edge. This kind of Connected Graph is known as the “Hamilton Graph.” The path you visit to verify if the given Graph is Hamilton Graph or not is known as Hamiltonian Path.

Here’s a simple example of a Hamilton graph:

In this image, we can visit all the vertices from any node in the above Graph. One of the paths can be A-D-C-H-B-E. It’s also possible to find a Hamilton Cycle. Hamilton Cycle starts and ends at the same vertex. So, the Hamilton Cycle will be A-D-C-H-B-E-A.

You're reading Types Of Graphs With Examples

## Core Commponents Of Hadoop With Examples

Hadoop Components are used to increase the data’s seek rate from the storage, as the data is increasing day by day. Despite storing the information in the warehouse, the seeking is not fast enough, making it unfeasible. To overcome this problem, Hadoop Components such as Hadoop Distributed file system aka HDFS (store data in the form of blocks in the memory), Map Reduce and Yarn, are used to allow the data to be read and process parallelly.

Start Your Free Data Science Course

The major components are described below:

1. Hadoop Distributed File System (HDFS)

HDFS is a master-slave architecture; it is NameNode as master and Data Node as a slave. NameNode is the machine where all the metadata is stored of all the blocks stored in the DataNode.

2. YARN

3. MapReduce

The Hadoop ecosystem is a cost-effective, scalable, and flexible way of working with such large datasets. Hadoop is a framework that uses a particular programming model, called MapReduce, for breaking up computation tasks into blocks that can be distributed around a cluster of commodity machines using the Hadoop Distributed Filesystem (HDFS).

MapReduce is two different tasks Map and Reduce, Map precedes the Reducer Phase. As the name suggests, the Map phase maps the data into key-value pairs; as we all know, Hadoop utilizes fundamental values for processing. The reducer phase is the phase where we have the actual logic to be implemented. Apart from these two phases, it executes the shuffle and sort phase as well.

Mapper: Mapper is the class where the input file is converted into keys and values pairs for further processing. While reading the data, it is read in fundamental values only where the key is the bit offset, and the value is the entire record.

E.g. we have a file chúng tôi in that we have two lines written, i.e. two records.

This is a wonderful day we should enjoy here, the offsets for ‘t’ is 0 and for ‘w’ it is 33 (white spaces are also considered as a character) so, the mapper will read the data as key-value pair, as (key, value), (0, this is a wonderful day), (33, we should enjoy)

Driver: Apart from the mapper and reducer class, we need one more Driver class. This code is necessary for MapReduce as it is the bridge between the framework and the logic implemented. It specifies the configuration, input data path, output storage path, and most importantly, which mapper and reducer classes need to be also implemented; many other arrangements be set in this class. e.g. in the driver class, we can specify the separator for the output file as shown in the driver class of the example below.

Example

Consider we have a dataset of travel agencies, now we need to calculate from the data that how many people choose to travel to a particular destination. To achieve this, we will need to take the goal as key, and for the count, we will take the value as 1. So, in the mapper phase, we will be mapping the destination to value 1. Now in the shuffle and sort phase after the mapper, it will map all the values to a particular key. E.g. if we have a destination as MAA, we have mapped 1 also we have 2 occurrences after the shuffling and sorting, we will get MAA,(1,1) where (1,1) is the value. Now, in the reducer phase, we already have a logic implemented in the reducer phase to add the values to get the total count of the ticket booked for the destination. This is the flow of MapReduce.

Below is the screenshot of the implemented program for the above example.

1. Driver Class

3. Reducer Class

For Execution of Hadoop, we first need to build the jar, and then we can achieve using the below command Hadoop jar chúng tôi chúng tôi /output.txt

Conclusion

Here we have discussed the core components of the Hadoop like HDFS, Map Reduce, and YARN. It is a distributed cluster computing framework that helps store and process the data and do the required analysis of the captured data. Hadoop is flexible, reliable in terms of data as data is replicated and scalable, i.e. we can add more machines to the cluster for storing and processing data.

Recommended Articles

This has been a guide to Hadoop Components. Here we discussed the core components of Hadoop with examples. You can also go through our other suggested articles to learn more –

## Working Of Mixin In Typescript With Examples

Introduction to TypeScript Mixins

Web development, programming languages, Software testing & others

Working of Mixin in Typescript with Examples

There is no particular syntax for writing mixin class as it is an extra class written to overcome the single inheritance problem, which means there is no restriction for extending a single class one at a time. Using mixin class is used in building simple partial classes, and this mixin class returns a new class. Therefore, the syntax of the mixin class cannot be defined exactly as it is a class that can take a constructor to create a class that has the functionalities of the constructor by extending the previous class and then returns a new class.

Suppose if we have two classes X and Y where class X wants to get the functionality of class Y, and this can be done using extending class X extends class Y, but in Typescript, mixins are used to extend the class Y, and therefore this function Y takes class X, and therefore it returns the new class with added functionality, and here the function Y is a mixin. In general, the mixin is a function that takes a constructor of the class to extend its functionality within the new class that is created, and this new class is returned.

The exact working of mixin can be demonstrated as a process of mixing multiple classes to a single target class, and this is done by using the “implement” keyword in Typescript for the target mixin class, which also uses some generic helper functions which helps to copy the properties of each mixin to the target mixin. But we cannot use interfaces as it can only extend the members of the class but not their implementations. Therefore, TypeScript provides mixins that help to inherit or extend from more than one class, and these mixins create partial classes and combine multiple classes to form a single class that inherits all the functionalities and properties from these partial classes.

Example of TypeScript Mixins

Different example are given below:

Example #1

Code:

console.log(" Demonstration of mixin using extends in Typescript") class Courses { name = ""; x = 0; y = 0; constructor(name: string) { this.name = name; } } return class Scaling extends Base { _scale = 1; setScale(scale: number) { this._scale = scale; } get scale(): number { return this._scale; } }; } const Institute = Scale(Courses); const numcourse = new Institute("Educba"); numcourse.setScale(3); console.log(numcourse.scale);

In the above program, we are first creating class “Courses” which we are trying to scale the number of courses in the institute but to extend this class property we are using mixin concept that is first take a constructor as to make mixin extend the class “Courses” with new functionalities and the constructor is defined using “constructor” keyword. Then to extend the class “Courses”, we need to use the keyword “extends”, which is done n the function Scale where we are extending the constructor of the class to create a new class and return that class. The output of the code can be seen in the screenshot, where we are inheriting the property setscale() by extending the constructor and creating a new class named “Institute”, which is extended by the “Course” class.

Now let us see another example where it will take multiple classes and how the mixin works.

Example #2 console.log(" Demonstration of mixin in Typescript ") class  Mathfunc{ calculate(): void { console.log("The math formula is getting executed"); } } class Variables { display(): void { console.log("The variables given are calculated and display the result"); } } class Add implements Mathfunc, Variables { a: number; b: number; constructor(a, b) { this.a = a; this.b = b; } res(): number { return this.a + this.b; } display(): void { } calculate(): void { } } function applyMixins(derivedCtor: any, baseCtors: any[]) { Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name)); }); }); } applyMixins(Add, [Mathfunc, Variables]); let p: Add = new Add(9, 7); p.calculate(); p.display(); let r = p.res(); console.log("The Additin of two given numbers  is as follows:"); console.log(r);

Output:

In the above program, we can see we have classes “mathfunc”, “variables”, and “Add” where t display we are just providing “implements” keyword to extend the class properties. We are providing empty implementations which mixin helper functions will later replace. Therefore this mixin created iterate through properties of the base classes and then copy all these properties from these single classes into one single target class, and this done in the function apply mixin in the above program. Therefore we are trying to calculate the sum of two numbers where we have created a constructor with two different variables, and the result is displayed using the res() function, which returns the sum.

Conclusion

This article concludes with a demonstration of mixin in typescript where we saw how mixin works with keyword “extends” and “implements”. In this article, we saw an example of demonstrating the mixin which supports single inheritance by using these keywords in the program. We should also note that it may take much time in compiling the above approaches.

Recommended Articles

We hope that this EDUCBA information on “TypeScript Mixins” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

## Different Types Of Frames In Html & Types Of Frame Tags

Introduction to Html Frames

Html frames are useful at dividing the web page or the web browser into multiple sections; they separate sections then load differently.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

A-frame displays content independent of its container. Multiple frames form a collection and are known as a frameset. The arrangement can be considered similar to the orientation of rows and columns in a table. The frame tag has been deprecated in HTML5.

Each frame has a frame tag to indicate. The horizontal frame is defined by the row attribute of the frame tag, and the vertical attribute is defined by the column attribute of the frame tag in the HTML document. The same window in one frame might display a static banner,  a second navigation menu, etc.

Syntax of Frames

Similarly, as we saw above, the attribute rows take the value in pixels, and they help at specifying the number and size of rows in a frameset.

Different Type of Frames in HTML

The different and some commonly used attributes in the frame are attributes such as border, scrolling, src, name, etc.

Types of Frame Tag

Following are the different types of frame tags:

1. Col: The col attribute gives the vertical frames. The width, however, can be specified in 4 ways:

Pixels: absolute values can be mentioned in pixels. If we have to create three vertical frames, we can give the value: cols=”100,50,100”.

Percentage: The percentage of the browser window can be mentioned. If we have to create three vertical frames, we can give the value: cols=”40%,20%,40%.”

We can also make use of the wildcard here (*) and let the wildcard take the remaining of the window, which remains un-mentioned.

cols=”30%,*,30%”

Output:

2. Rows: The row attribute gives the horizontal frames. It specifies the rows in a frameset. If we have to create three horizontal frames we use:

Eg: Rows=”10%,80%,10%’.

We can also set the height of each row as we had done in the case of columns previously.

Output:

3. Border: It specifies the width of the border of each frame in pixels.

E.g., border=”4”. If border=”0”, it means there is no border.

4. Frameborder: If a three-dimensional border needs to be displayed between frames, then we use this attribute. The value which the attribute takes is either 1 or 0 ( Yes or No).

E.g.: frameborder=”0” means no border.

5. Framespacing: This attribute specifies the amount of space between frames in a frameset. Any integer value can be given here for this attribute.

E.g., framespacing=”12” means between the frames, there should be the spacing of 12 pixels.

There are 8 attributes that can be listed here in this section.

1. src: We provide the file name to this attribute that is supposed to be loaded into the frame. The value of this attribute can be any URL.

E.g., name=”abc.htm.”

3. frameborder: This attribute is specified to show if the borders are to be shown or not. The value takes up is 1 or 0 (Yes or No).

4. marginwidth: The attribute is helpful at specifying the width of the space between the left and right of the frame’s border and also the content of the frame. The value is given in pixel.

5. marginheight: The attribute is helpful at specifying the height of the space between the top and the bottom of the frame’s border and also the content of the frame. The value is given in pixel.

E.g., marginheight=”10”.

6. noresize: This attribute basically prevents the user from making any changes to the already present frames. In the absence of this attribute, any frame can be resized.

E.g., noresize=”noresize.”

7. scrolling: This attribute takes control of the appearance of the scroll bars, which are present on the frame. The value either a ‘yes, ‘no’, or ‘auto’.

E.g., scrolling=” no” means it should not have scroll bars.

8. longdesc: This attribute lets you provide a link to another page containing a long description of the content of the frame.

E.g., longdesc=”framedesc.htm.”

Frames and Browser Support

It is a nice approach to put up a message in such scenarios for the user who use old browsers. Messages like “ Sorry! Your browser does not support frames.” to notify.

Conclusion

Frame technology is not supported by quite a number of browsers these days. It is often noticed that the contents of the web page are not displayed properly for smaller devices. Anyway, it is good to have knowledge of what existed so that better models could be developed to be compatible with new technologies.

Recommended Articles

This is a guide to Html Frames. Here we discuss the different types of Frames in HTML and the Types of Frame Tag with Frames and Browser Support. You may also look at the following article to learn more –

## Learn Working Of Json In Swift With Examples

Introduction to Swift JSON

Swift JSON is used for communication of the IOS web application with the server by returning a series of formatted data or information. This formatted data organized in a proper hierarchical manner is called Swift JSON. Foundation framework that includes a class called JSONSerialization is exclusively used for converting any JSON involved within the web application into Swift data types like array, number, bool, String, and Dictionary. It is very difficult to predict the actual structure or the order in which values of JSON-based web applications will receive as part of returned data.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

There is no proper syntax for any Swift JSON it can be any resource file containing the data in an ordered manner as represented below but then indentation does matter while validating any JSON data as improper JSON input might vary and can behave differently while parsing and traversing as well.

{ "title": "some_data", "url": "any_url_can_be_included", "category": "Category_for_swift_language", "views": 25648 } How JSON works in Swift?

JSON parsing or manipulation with JSON in any programming language is a common functionality when any web application tries to communicate with the other server.

Any web application dealing with JSON data tries to decode the JSON data in an ordered manner. Swift JSON parsing is very important for any IOS developer as they will most often get acquainted with these kinds of data.

Decoding modules in swift are quite flexible and are very easy to understand without any indulgence of external API.

There are times when swift JSON containing JSONSerialization class method returns a value of any type and throws error in case the data cannot get parsed easily then a proper validation with error elicitation will be given to the user for identification of the actual exception.

Although the JSON data will get validated still there will be times when JSON may contain a single value, a response from a web application can encode an object or array as any top-level object for manipulation.

All the data types related to swift get used as per requirement and any optional value can be considered for it.

There is quite a need to create Model objects from the Model-view-controller design pattern that are often used to convert json data to objects which are specific to the application’s domain in a model view.

If the applications are related to one or more web services do not return a single, or consistent model for the representation of a model object, considering implementation of several initializers to handle all the possible representations.

JSON initializer helps a lot when it comes to extracting and getting the detailed implementation with errors and exceptions. Error Handling with error protocols helps in deserialization with the fail for protocol.

Many times, it happens that the application returns multiple endpoints for any resource that returns a single JSON response following any particular protocol.

A search endpoint may return zero or more endpoints then in that case the requested query may contain more or other metadata while presenting for the endpoint.

JSON parser plays a pivotal role in parsing as it helps in making the entire JSON data organized in a properly visualized format which gives an impression that the data can be organized in a proper manner.

Swift is the programming language that allows programmers to use and make the data ordered and visualized in a very easy and effective manner by giving an idea of proper idealization and organization for operations and manipulations.

Examples of Swift JSON

Here are the following examples mentioned below.

Example #1

This program demonstrates the JSON data where the input feed is represented as follows and the output feed after execution of the JSON parsing comes out to be shown as output. But it makes the Sample usage feed with the codeable mapping.

Code:

{ "title": "Usage of the optional Swift language.", "version": "4.0", "category": "Swift_version", "views": 25642 }

Output:

Example #2

This program demonstrates the JSON data where the input feed is represented with the same input as example 1 but with the mere difference of the fact that the JSON decoder will make use of the Object mapper for conversion of JSON String to model. This is shown in the output as shown:

Code:

{ "title": "Usage of the optional Swift language.", "version": "4.0", "category": "Swift_version", "views": 25642 }

Output:

Example #3

This program demonstrates the JSON data where the input feed is represented with the same input as example 1 but with the more difference of the fact that the JSON decoder will make use of the dictionary mapper for conversion of JSON String to model. This is shown in the output as shown:

{ "title": "Usage of the optional Swift language.", "version": "4.0", "category": "Swift_version", "views": 25642 }

Output:

Example #4

This program demonstrates the custom mapping for each defined key with the mapping of a blog and key and value pairs with the JSON and making the key encoding as the main conversion of the JSON to a blog.

Code:

{ "title": "Sat_Sun_Week:end_Comboff", "version": "swift_version_4.0", "visitors_way": 258965, "posts_for_members": 62542 }

Output:

Example #5

This program demonstrates the custom mapping for each defined key with the mapping of a blog and key and value pairs with the JSON and making the Object mapper in use for representation as shown in the output.

{ "title": "Sat_Sun_Week:end_Comboff", "version": "swift_version_4.0", "visitors_way": 258965, "posts_for_members": 62542 }

Output:

Example #6

This program demonstrates the custom mapping for each defined key with the mapping of a blog, key and value pairs with the JSON and making the Dictionary mapper in use for representation as shown in the output.

Code:

{ "title": "Sat_Sun_Week:end_Comboff", "version": "swift_version_4.0", "visitors_way": 258965, "posts_for_members": 62542 }

Output:

Conclusion

Swift JSON is the proper way of validating and making the entire data set and information organized in a visualized manner for the programmers. The successful communication between any web application and server helps a lot to analyze the entire application for product analysis and division of information uniformly among all applications efficiently.

Recommended Articles

This is a guide to Swift JSON. Here we discuss the introduction, syntax, and working of Swift JSON along with examples and code implementation. You may also have a look at the following articles to learn more –

## Working Of Bless() Function In Perl With Examples

Introduction to Perl bless function

Web development, programming languages, Software testing & others

Working of bless() function in Perl with examples

In this article, we will discuss a built-in function where to make the program understand that the variable can be made an object of a particular class in Perl, where this function is known as the bless() function. Unlike in other programming languages, Perl creates an object similar to creating or declaring variables. Therefore the Perl programming language provides a built-in function called bless() function, which makes the variable look like an object of the particular class that it belongs to.

Now let us see the syntax and examples of how the bless() function works in the below example.

Syntax:

bless var_ref, class_name;

Parameters:

var_ref: this parameter refers to the variable as an object of the class whose class name is specified.

class_name: This parameter specifies the class name to which the object is created by marking the variable reference as an object of this class specified in this parameter.

This function can take only var_ref as an argument also, and this function returns the reference of the marked variable as a reference to an object blessed into a particular or specified class name as specified in the arguments passed to the function.

Examples

Now let us see a simple example of demonstrating the bless() function in the below section.

Example #1 use strict; use warnings; print "Demonstration of bless() function in Perl."; print "n"; print "n"; package student_data; sub stud { my \$class_name = shift; my \$var_ref = { }; print "The bless() function is now implemented:"; print "n"; bless \$var_ref, \$class_name; return \$var_ref; } print "Object creation"; print "n"; print "n"; my \$info = stud student_data("Alen","Python",32); print "The student's name is :"; print "n"; print "n"; print "The course name student taken is:"; print "n"; print "n"; print "The student's age is :"; print "n"; print "n";

Output:

In the above program, we can see we have defined class “stud” using a keyword package in Perl. Then we created a subroutine to print the student’s details. In this variable, we are referring each variable to the class name using the variable reference to object creation and class name as arguments in the bless() function in the above program. Then we are printing each value of the objects created.

Now we will see bless function taking only one argument and two arguments in the example below.

Example #2 use strict; use warnings; print "Demonstration of bless() function in Perl."; print "n"; print "n"; package student_data; sub stud { my \$class_name = shift; my \$var_ref = { }; print "The bless() function is now implemented:"; print "n"; bless \$var_ref; return \$var_ref; } package Employee; sub emp { my \$class2 = shift; my \$var_ref2 = { }; bless \$var_ref2, \$class2; return \$var_ref2; } print "Object creation"; print "n"; print "n"; print "Bless function takes only one argument:"; print "n"; print "n"; my \$info = stud student_data("Alen","Python",32); print "The student's name is :"; print "n"; print "n"; print "The course name student taken is:"; print "n"; print "n"; print "The student's age is :"; print "n"; print "n"; print "Bless() function takes two argument:"; print "n"; print "n"; my \$per_info = emp Employee("Ram", "Shukla", 343); print "The employee's name is :"; print "n"; print "n"; print "The employee's second name student taken is:"; print "n"; print "n"; print "The employee's employee number is :"; print "n"; print "n";

Output:

In the above program, we can see we have declared two classes “student_data” and “Employee” wherein the class “Student_data” we have defined function bless() with the single argument so when the variables reference is only passed, it will by default, take only the values of its current class but not of the “employee” class.

Conclusion

In this article, we conclude that the bless() function is a built-in function in Perl for marking the variables reference to object creation which belongs to the particular class with its class name specified as an argument in the bless() function. In this article, we have seen examples of bless() function taking two arguments and what happens if there are two classes and the class name is not specified as an argument in the function, which will, by default, take the current class name.

Recommended Articles

This is a guide to Perl bless. Here we discuss the introduction and Working of bless() function in Perl with examples for better understanding. You may also have a look at the following articles to learn more –

Update the detailed information about Types Of Graphs With Examples on the Achiashop.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!