- Home
- Interview Questions
- Perl
Each pattern system variable is defined only in the current subroutine or block of statements.
A server process that is listening for clients is like an electrical socket on the wall. any client process with the appropriate protocol can "plug into" it.
Basically, to keep Perl programs from blowing up if they try to access a variable that has not yet been assigned to.
No. If you need to access the elements of an associative array in a specified order, use keys and sortto sort the subscripts, and then retrieve the value associated with each element.
No. If you are likely to need the subscripts as well as their values, use eachor keys.
Packages are used to, well, package sets of global variables in a single unit, such that those units can be combined without one unit’s variables tromping over another’s. Packages work best for scripts that are made up of lots of parts that must work in harmony, or for modules of reusable library code.
The full package name for any variable or subroutine consists of the variable symbol ($ for scalars, @ for arrays, % for hashes, & for subroutine calls), the package name, two colons, and the variable name, for example, $AModule::avariable or &38;Amodule::asubroutine$40;&41;.
Declaring global variables with my prevents them from being declared in the main package, which makes them slightly more efficient for value lookup and assignment, as well as making your script more well-behaved should it ever be incorporated into a package or combined with other scripts.
use strict is a special Perl directive that makes sure all the variables in your script are local variables or assigned to a particular package. At this point in your Perl knowledge, it’s most useful for catching random global variables and making sure your scripts are self-contained as far as variable declarations go.
Libraries are collections of Perl code intended to be reused. Libraries can use packages to manage variable names inside that library. A module is a library that uses a package and has the same filename as that package. Modules include code that allows that module to be reused easily in other scripts. A pragma is a special kind of module that affects Perl’s operation during both compile time and runtime.