Found 26504 Articles for Server Side Programming

How to convert a string to a number in Perl?

Mukul Latiyan
Updated on 04-Apr-2023 15:47:18

3K+ Views

In Perl, we can convert a string into a number by appending the integer value 0 in front of it. There are some other approaches too, which we will discuss in this tutorial with the help of examples. Example Let's first consider the case where the string that we are trying to convert looks something like "123abc" or "23Hzbc". You can see that the it is a mixture of both integer values and characters. Consider the code shown below. my $firstStr = '23ASDF'; print "Convering First String to Number: ", $firstStr + 0; print ""; my $secondStr = ... Read More

How to compare two strings in Perl?

Mukul Latiyan
Updated on 04-Apr-2023 15:46:09

8K+ Views

Perl has methods and operators that determine whether two string values are equal or different. In Perl, the compare strings function is essential for comparing two strings and their values. This check examines if two string values are equal or not by using the "eq" and "ne" operators. We can also compare two strings with the help of the "lt, gt, ge, le" operators as well. In this tutorial, we will consider all the approaches that can be used to compare two strings in Perl. The "eq" and "ne" Operators in Perl Let's start with the eq and ... Read More

Golang program to print pointer to a struct

Akhil Sharma
Updated on 04-Apr-2023 12:10:14

2K+ Views

In this article, we will write Golang programs to print pointer to a struct. A pointer stores the address of the memory location where the variable’s value is placed. We can the access the address of the variable using & operator. For ex= &a tell the address of the a. Example 1 In this example, we will write a Golang program to show the pointer to a struct by creating a child struct and printing the pointer to that struct. package main import "fmt" type Child struct { name string age ... Read More

Golang program to demonstrate passing of pointers to a function

Akhil Sharma
Updated on 04-Apr-2023 12:09:16

302 Views

In this Golang article, we will write programs to demonstrate passing of pointers to a function suing increment and Swapping approach. A pointer stores the address of another variable. For ex- var *a = &b. Here a is the pointer that stores the address of b which means a can access the value of b as it stores the address of b. Using the Increment Approach In this method, we will write a Golang program to demonstrate the passing of pointers to a function by using an increment function where we use pointers to point to the variable which is ... Read More

Golang program to implement returning pointer from a function

Akhil Sharma
Updated on 04-Apr-2023 12:08:17

669 Views

In this article, we will write Golang programs to implement returning pointer from a function. A pointer stores the address of another variable and the address is depicted using & operator. Algorithm Step 1 − Create a package main and declare fmt(format package) package in the program where main produces executable codes and fmt helps in formatting input and Output. Step 2 − Create a function create_pointer that returns a pointer to the int Step 3 − Set the value of x in the function and return the variable back to the function Step 4 − Create a main ... Read More

Golang program to parse time

Akhil Sharma
Updated on 04-Apr-2023 12:07:54

2K+ Views

In golang we can use various internal time function to parse time. Time is parsed using parse and ParseInLocation method. Syntax time.Parse() This function belongs to time package. It is used to parse the string into time.Time value and it takes two inputs: the layout and the time string which is to be parsed. time.ParselnLocation() This function is a part of the time package. It is used to parse the string into time.Time value along with a specified location. It takes 3 arguments: the location, layout string and the time string. time.Format() This function is present in ... Read More

Golang program to implement select statement

Akhil Sharma
Updated on 04-Apr-2023 12:07:17

370 Views

The Golang Select statement is similar to the switch statement, the switch statement selects the Output based on the cases but here the Output is selected based on which communication occurs fast in the channels. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments. time.Sleep() This function belongs to the time package. Here, the word sleep depicts the meaning of the function which says that it will block the execution of goroutine for ... Read More

Golang program to show promoted methods

Akhil Sharma
Updated on 04-Apr-2023 12:06:19

483 Views

In golang, Promoted methods are the methods created under those structs which are embedded inside another struct, now the struct in which it is embedded can access its methods and fields. In this article we are going to explain how to show promoted methods using various structs like Rectangle and Square, Vehicle and car. Algorithm Step 1 − Create a package main and declare fmt(format package) package in the program where main produces executable codes and fmt helps in formatting input and Output. Step 2 − Create a Rectangle struct with two fields width and height of type float ... Read More

Golang program to depict use of promoted fields

Akhil Sharma
Updated on 04-Apr-2023 12:05:17

451 Views

In golang, promoted fields are the structs that are embedded inside another structs and their fields can also be accessed the structs in which they are embedded. In this article we are going to understand three different approaches to depict use of promoted filed with and without the help of pointers. Using Pointers In this illustration, we will make use of pointers to show the promoted fields. The field names will be set with the help of pointers and information will be printed using dot notation. Algorithm Step 1 − Create a package main and declare fmt(format package) package ... Read More

Golang program to show use of rand package

Akhil Sharma
Updated on 04-Apr-2023 12:02:21

367 Views

In golang, a rand package is used to generate random numbers/characters. Firstly, it seeds with the current time to get the different random Output each time then perform any operation. Syntax rand.Seed(value) Rand.Seed() function is used to generate random numbers. It takes a user input as argument which is the upper limit for generating random numbers. func Now() Time The Now() function is defined in time package. This function generates the current local time. To use this function, we have to first impot the time package in our program. func (t Time) UnixNano() int64 The UnixNano() function ... Read More

Advertisements