Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 2066 of 2650
4K+ Views
The croak function in Perl is equivalent to die, except that it reports the caller one level up. Like die, this function also exits the script after reporting the error to STDERR −package T; require Exporter; @ISA = qw/Exporter/; @EXPORT = qw/function/; use Carp; sub function { croak "Error in module!"; } 1;When called from a script like below −use T; function();It will produce the following result −Error in module! at test.pl line 4As with carp, the same basic rules apply regarding the including of line and file information according to the warn and die functions.
1K+ Views
The cluck function in Perl is a sort of supercharged carp, it follows the same basic principle but also prints a stack trace of all the modules that led to the function being called, including the information on the original script.package T; require Exporter; @ISA = qw/Exporter/; @EXPORT = qw/function/; use Carp qw(cluck); sub function { cluck "Error in module!"; } 1;When called from a script like below −use T; function();It will produce the following result −Error in module! at T.pm line 9 T::function() called at test.pl line 4
1K+ Views
The carp function in Perl is the basic equivalent of warn and prints the message to STDERR without actually exiting the script and printing the script name.package T; require Exporter; @ISA = qw/Exporter/; @EXPORT = qw/function/; use Carp; sub function { carp "Error in module!"; } 1;When called from a script like below −use T; function();It will produce the following result −Error in module! at test.pl line 4
225 Views
There are two different situations we should be able to handle while using Perl Programming −Reporting an error in a module that quotes the module's filename and line number - this is useful when debugging a module, or when you specifically want to raise a module-related, rather than script-related, error.Reporting an error within a module that quotes the caller's information so that you can debug the line within the script that caused the error. Errors raised in this fashion are useful to the end-user, because they highlight the error in relation to the calling script's origination line.The warn and die ... Read More
1K+ Views
The unless function in Perl is the logical opposite to if: statements can completely bypass the success status and only be executed if the expression returns false. For example −unless(chdir("/etc")) { die "Error: Can't change directory - $!"; }The unless statement is best used when you want to raise an error or alternative only if the expression fails. The statement also makes sense when used in a single-line statement −die "Error: Can't change directory!: $!" unless(chdir("/etc"));Here we die only if the chdir operation fails.The die FunctionThe die function works just like warn, except that it also calls exit. Within ... Read More
4K+ Views
You can use mkdir function in Perl to create a new directory. You will need to have the required permission to create a directory.#!/usr/bin/perl $dir = "/tmp/perl"; # This creates perl directory in /tmp directory. mkdir( $dir ) or die "Couldn't create $dir directory, $!"; print "Directory created successfully";Remove a directoryYou can use rmdir function in Perl to remove a directory. You will need to have the required permission to remove a directory. Additionally this directory should be empty before you try to remove it.#!/usr/bin/perl $dir = "/tmp/perl"; # This removes perl directory from /tmp directory. rmdir( $dir ) or die "Couldn't ... Read More
788 Views
There are various ways to list down all the files available in a particular directory using Perl. First let's use the simple way to get and list down all the files using the glob operator −#!/usr/bin/perl # Display all the files in /tmp directory. $dir = "/tmp/*"; my @files = glob( $dir ); foreach (@files ) { print $_ . ""; } # Display all the C source files in /tmp directory. $dir = "/tmp/*.c"; @files = glob( $dir ); foreach (@files ) { print $_ . ""; } # Display all the hidden files. $dir = "/tmp/.*"; @files ... Read More
4K+ Views
The following C++ program illustrates how to remove the vowels (a, e, i, u, o) from a given string. In this context, we create a new string and process input string character by character, and if a vowel is found it is excluded in the new string, otherwise the character is added to the new string after the string ends we copy the new string into the original string. The algorithm is as follows;AlgorithmSTART Step-1: Input the string Step-3: Check vowel presence, if found return TRUE Step-4: Copy it to another array Step-5: Increment the counter ... Read More
3K+ Views
This article is serving the purpose of validating the correct IP (internet protocol) address by virtue of C++ code programming. The IP address is a 32-bit dot-decimal-notation, broken into four decimal numbers segments ranging from 0 to 255. Furthermore, these numbers are separated by dots consecutively. The IP address serves the purpose of identifying a host machine in the network in a unique manner in order to establish a connection among them.So, in order to validate the correct IP address input from the user-end, the following algorithm briefs how exactly the code sequence is materialized to identify the correct IP ... Read More
706 Views
This aim of this program to replace a particular word with asterisks in the string by using the c++ programming code. The essential function of vector and string class essay a key role to achieve the prospective results. The algorithm is as follows;AlgorithmSTART Step-1: Input string Step-2 Split the string into words and store in array list Step-3: Iterate the loop till the length and put the asterisk into a variable Step-4: Traverse the array foreah loop and compare the string with the replaced word Step-5: Print ENDNow, the following code is carved out based ... Read More