Mohd Mohtashim

Mohd Mohtashim

185 Articles Published

Articles by Mohd Mohtashim

Page 8 of 19

Temporary Values via local() in Perl

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

The local is mostly used when the current value of a variable must be visible to called subroutines in Perl. A Perl local just gives temporary values to global (meaning package) variables. This is known as dynamic scoping. Lexical scoping is done with my, which works more like C's auto declarationsIf more than one variable or expression is given to local, they must be placed in parentheses. This operator works by saving the current values of those variables in its argument list on a hidden stack and restoring them upon exiting the block, subroutine, or eval.ExampleLet's check the following example ...

Read More

State Variables via state() in Perl

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

There is another type of lexical variable in Perl, which is similar to private variables but they maintain their state and they do not get reinitialized upon multiple calls of the subroutines. These variables are defined using the state operator and available starting from Perl 5.9.4.ExampleLet's check the following example to demonstrate the use of state variables −#!/usr/bin/perl use feature 'state'; sub PrintCount {    state $count = 0; # initial value    print "Value of counter is $count";    $count++; } for (1..5) {    PrintCount(); }OutputWhen the above program is executed, it produces the following result −Value of ...

Read More

Dereferencing in Perl

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

Dereferencing in Perl returns the value from a reference point to the location. To dereference a reference simply use $, @ or % as a prefix of the reference variable depending on whether the reference is pointing to a scalar, array, or hash. Following is the example to explain the concept −Example#!/usr/bin/perl $var = 10; # Now $r has reference to $var scalar. $r = \$var; # Print value available at the location stored in $r. print "Value of $var is : ", $$r, ""; @var = (1, 2, 3); # Now $r has reference to @var ...

Read More

Circular References in Perl

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

A circular reference in Perl occurs when two references contain a reference to each other. You have to be careful while creating references otherwise a circular reference can lead to memory leaks. Following is an example −Example#!/usr/bin/perl my $foo = 100; $foo = \$foo; print "Value of foo is : ", $$foo, "";OutputWhen the above program is executed, it produces the following result −Value of foo is : REF(0x9aae38)

Read More

References to Functions in Perl

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

While using Perl script, this might happen if you need to create a signal handler so you can produce a reference to a function by preceding that function name with \& and to dereference that reference you simply need to prefix reference variable using ampersand &. Following is an example −Example#!/usr/bin/perl # Function definition sub PrintHash {    my (%hash) = @_;    foreach $item (%hash) {       print "Item : $item";    } } %hash = ('name' => 'Tom', 'age' => 19); # Create a reference to above function. $cref = \&PrintHash; # Function call using reference. ...

Read More

How to use Formats in Perl?

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

In order to invoke a format declaration in Perl Script, we would use the write keyword −write EMPLOYEE;The problem is that the format name is usually the name of an open file handle, and the write statement will send the output to this file handle. As we want the data sent to the STDOUT, we must associate EMPLOYEE with the STDOUT filehandle. First, however, we must make sure that that STDOUT is our selected file handle, using the select() function.select(STDOUT);We would then associate EMPLOYEE with STDOUT by setting the new format name with STDOUT, using the special variable $~ or $FORMAT_NAME as ...

Read More

Create a Report Header using Perl

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

Sometime you would be interested in adding a header to your report. This header will be printed on top of each page. It is very simple to do this using Perl. Apart from defining a template you would have to define a header and assign it to $^ or $FORMAT_TOP_NAME variable −Example#!/usr/bin/perl format EMPLOYEE = =================================== @

Read More

How to create an image to zoom with CSS and JavaScript?

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

Following is the code to create an image zoom:Example    * {box-sizing: border-box;}    .img{       display: inline-block;    }    .img-zoom-container {       position: relative;    }    .img-zoom-zoomLens {       position: absolute;       border: 1px solid #d4d4d4;       width: 50px;       height: 50px;    }    .myresult{       display: inline-block;    }    .img-zoom-result {       border: 1px solid #d4d4d4;    } Image Zoom Example Hover over the image on the ...

Read More

Creating Instance Objects in Python

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

To create instances of a class, you call the class using class name and pass in whatever arguments its __init__ method accepts."This would create first object of Employee class" emp1 = Employee("Zara", 2000) "This would create second object of Employee class" emp2 = Employee("Manni", 5000)You access the object's attributes using the dot (.) operator with object. Class variable would be accessed using class name as follows −emp1.displayEmployee() emp2.displayEmployee() print "Total Employee %d" % Employee.empCountExampleNow, putting all the concepts together −#!/usr/bin/python class Employee:    'Common base class for all employees'    empCount = 0    def __init__(self, name, salary):       self.name ...

Read More

Parsing XML with DOM APIs in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 31-Jan-2020 2K+ Views

The Document Object Model ("DOM") is a cross-language API from the World Wide Web Consortium (W3C) for accessing and modifying XML documents.The DOM is extremely useful for random-access applications. SAX only allows you a view of one bit of the document at a time. If you are looking at one SAX element, you have no access to another.Here is the easiest way to quickly load an XML document and to create a minidom object using the xml.dom module. The minidom object provides a simple parser method that quickly creates a DOM tree from the XML file.The sample phrase calls the ...

Read More
Showing 71–80 of 185 articles
« Prev 1 6 7 8 9 10 19 Next »
Advertisements