Articles on Trending Technologies

Technical articles with clear explanations and examples

Tutorix - AI Tutor

POSIX Function strftime() in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 17K+ Views

You can use the POSIX function strftime() in Perl to format the date and time with the help of the following table. Please note that the specifiers marked with an asterisk (*) are locale-dependent.SpecifierReplaced byExample%aAbbreviated weekday name *Thu%AFull weekday name *Thursday%bAbbreviated month name *Aug%BFull month name *August%cDate and time representation *Thu Aug 23 14:55:02 2001%CA year divided by 100 and truncated to integer (00-99)20%dDay of the month, zero-padded (01-31)23%DShort MM/DD/YY date, equivalent to %m/%d/%y08/23/01%eDay of the month, space-padded ( 1-31)23%FShort YYYY-MM-DD date, equivalent to %Y-%m-%d2001-08-23%gWeek-based year, last two digits (00-99)01%GWeek-based year2001%hAbbreviated month name * (same as %b)Aug%HAn hour in 24h ...

Read More

Find maximum in stack in O(1) without using additional stack in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 725 Views

Suppose we want to make a stack that can store the maximum element in the stack. And we can get it in O(1) time. The constraint is that, it should not use any additional space, so O(1) extra space.We can make one user-defined stack, that will store the max value, when one operation is performed, like pop or peek, then the max will be returned. For peek operation, return the maximum of stack top and the max element, for pop operation, when the top element is larger, then print it and update max as 2*max – top_element. otherwise return top_element. ...

Read More

Define and Call a Subroutine in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 359 Views

The general form of a subroutine definition in Perl programming language is as follows −sub subroutine_name {    body of the subroutine }The typical way of calling that Perl subroutine is as follows −subroutine_name( list of arguments );In versions of Perl before 5.0, the syntax for calling subroutines was slightly different as shown below. This still works in the newest versions of Perl, but it is not recommended since it bypasses the subroutine prototypes.&subroutine_name( list of arguments );Let's have a look into the following example, which defines a simple function and then call it. Because Perl compiles your program before ...

Read More

Passing Arguments to a Subroutine in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 2K+ Views

You can pass various arguments to a Perl subroutine like you do in any other programming language and they can be accessed inside the function using the special array @_. Thus the first argument to the function is in $_[0], the second is in $_[1], and so on.You can pass arrays and hashes as arguments like any scalar but passing more than one array or hash normally causes them to lose their separate identities. So we will use references ( explained in the next chapter ) to pass an array or hash.Let's try the following example, which takes a list ...

Read More

Find minimum number of currency notes and values that sum to given amount in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we have such amount, and we have to find the minimum number of notes of different denominations, that sum up to the given amount. Start from highest denomination notes, try to find as many notes possible for given amount. Here the assumption is that we have infinite amount of {2000, 500, 200, 100, 50, 20, 10, 5, 2, 1}. So if the amount is say 800, then notes will be 500, 200, 100.Here we will use the greedy approach to solve this problem.Example#include using namespace std; void countNotes(int amount) {    int notes[10] = { 2000, 500, 200, 100, ...

Read More

Passing Lists to Subroutines in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 982 Views

Because the @_ variable is an array in Perl, it can be used to supply lists to a subroutine. However, because of the way in which Perl accepts and parses lists and arrays, it can be difficult to extract the individual elements from @_. If you have to pass a list along with other scalar arguments, then make list as the last argument as shown below −Example#!/usr/bin/perl # Function definition sub PrintList {    my @list = @_;    print "Given list is @list"; } $a = 10; @b = (1, 2, 3, 4); # Function call with list parameter ...

Read More

Find profession in a special family in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 247 Views

Consider there is a special family of doctors and engineers. There are some rules, these are like below −Everybody has two childrenFirst child of an engineer is an engineer, second child is doctorFirst child of a doctor is a doctor, second child is an engineerAll generations of doctors and engineers starts with engineerSo if we want to get result for level 4 and pos 2, then result will be DoctorThe idea is simple. Profession of a person depends on following two.Profession of the parent.Position of node: When the position of a node is odd, then its profession is same as ...

Read More

Passing Hashes to Subroutines in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 2K+ Views

When you supply a hash to a Perl subroutine or operator that accepts a list, then the hash is automatically translated into a list of key/value pairs. For example −Example#!/usr/bin/perl # Function definition sub PrintHash {    my (%hash) = @_;    foreach my $key ( keys %hash ) {       my $value = $hash{$key};       print "$key : $value";    } } %hash = ('name' => 'Tom', 'age' => 19); # Function call with hash parameter PrintHash(%hash);OutputWhen the above program is executed, it produces the following result −name : Tom age : 19

Read More

Find relative complement of two sorted arrays in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 520 Views

Suppose we have two sorted arrays arr1 and arr2, there sizes are m and n respectively. We have to find relative complement of two arrays. It means that we need to find all those elements which are present in arr1, but not in arr2. So if the arrays are like A = [3, 6, 10, 12, 15], and B = [1, 3, 5, 10, 16], then result will be [6, 12, 15]To solve this, we can use the set_difference function. As the problem is basically set difference operation.Example#include #include #include using namespace std; int main() {    int first[] = ...

Read More

Returning Value from a Subroutine in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 5K+ Views

You can return a value from Perl subroutine as you do in any other programming language. If you are not returning a value from a subroutine then whatever calculation is last performed in a subroutine is automatically also the return value.You can return arrays and hashes from the subroutine like any scalar but returning more than one array or hash normally causes them to lose their separate identities. So we will use references ( explained in the next chapter ) to return an array or hash from a function.ExampleLet's try the following example, which takes a list of numbers and ...

Read More
Showing 28621–28630 of 61,297 articles
Advertisements