Mohd Mohtashim has Published 251 Articles

Regular Expression Special Variables in Perl

Mohd Mohtashim

Mohd Mohtashim

Updated on 29-Nov-2019 11:52:35

551 Views

There are various Regular Expression Special Variables in Perl. We have listed them in different below in tabular form −$digitContains the text matched by the corresponding set of parentheses in the last pattern matched. For example, $1 matches whatever was contained in the first set of parentheses in the previous ... Read More

Global Special Variable Types in Perl

Mohd Mohtashim

Mohd Mohtashim

Updated on 29-Nov-2019 11:51:07

300 Views

There are various global special variables in Perl. We have listed them in different blocks based on their usage and nature −Global Array Special Variables@ARGVThe array containing the command-line arguments intended for the script.@INCThe array containing the list of places to look for Perl scripts to be evaluated by the ... Read More

The confess Function in Perl

Mohd Mohtashim

Mohd Mohtashim

Updated on 29-Nov-2019 11:49:28

1K+ Views

The confess function in Perl is like cluck; it calls die and then prints a stack trace all the way up to the origination script.package T; require Exporter; @ISA = qw/Exporter/; @EXPORT = qw/function/; use Carp; sub function {    confess "Error in module!"; } 1;When called from a script ... Read More

The croak Function in Perl

Mohd Mohtashim

Mohd Mohtashim

Updated on 29-Nov-2019 11:47:44

3K+ 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 ... Read More

The cluck Function in Perl

Mohd Mohtashim

Mohd Mohtashim

Updated on 29-Nov-2019 11:46:36

709 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/; ... Read More

The carp Function in Perl

Mohd Mohtashim

Mohd Mohtashim

Updated on 29-Nov-2019 11:44:40

822 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 ... Read More

Errors within Perl Modules

Mohd Mohtashim

Mohd Mohtashim

Updated on 29-Nov-2019 11:42:46

127 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 ... Read More

The unless & die Function in Perl

Mohd Mohtashim

Mohd Mohtashim

Updated on 29-Nov-2019 11:41:22

781 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 ... Read More

Create, Delete and Change Directories in Perl

Mohd Mohtashim

Mohd Mohtashim

Updated on 29-Nov-2019 11:39:54

3K+ 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 ... Read More

Display all the Files in Perl

Mohd Mohtashim

Mohd Mohtashim

Updated on 29-Nov-2019 11:26:37

528 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( ... Read More

Advertisements