Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
statements have a value, and thus are also expressions and can be used
in larger expressions themselves.
Perl 5 added features that support complex data structures, firstclass functions (that is, closures as values), and an object-oriented
programming model. These include references, packages, class-based
method dispatch, and lexically scoped variables, along with compiler
directives (for example, the strict pragma). A major additional feature
introduced with Perl 5 was the ability to package code as reusable
modules. Wall later stated that "The whole intent of Perl 5's module
system was to encourage the growth of Perl culture rather than the Perl
core."
All versions of Perl do automatic data-typing and automatic memory
management. The interpreter knows the type and storage requirements of
every data object in the program; it allocates and frees storage for them
as necessary using reference counting (so it cannot de-allocate circular
data structures without manual intervention). Legal type conversions
for example, conversions from number to string are done automatically
at run time; illegal type conversions are fatal errors.
perl -v
This will display the information of installed PERL version.
COMMENTS:
Text starting from a "#" character until the end of the line is a
comment, and is ignored.
DATA TYPES:
Many of Perl's syntactic elements are optional. Rather than requiring
you to put parentheses around every function call and declare every
variable, you can often leave such explicit elements off and Perl will figure
out what you meant. This is known as Do What I Mean, abbreviated DWIM.
SCALAR:
A scalar is the simplest kind of data that Perl manipulates. They are
preceded by a dollar sign ($). A scalar is either a number, a string, or a
reference. A reference is actually an address of a variable which we will
see in upcoming chapters.
A scalar value can be acted upon with operators (like plus or
concatenate), generally yielding a scalar result. A scalar value can be
stored into a scalar variable. Scalars can be read from files and devices
and written out as well.
A number can be an integer number or a float. All are stored as C
double precision float numbers internally. A number can be specified as
decimal, octal, hexadecimal. All numbers are accessible as strings also. By
default, all the numbers are stored and processed as DECIMAL only. To
print in Hexa, Octal, Binary, scientific PRINTF() has to be used.
12
: integer
-2348
: integer ve
3.1412
-23.5e-4
: float number
: float number ve
017
-017
: octal number
: octal number -ve
0x8AE
-0x12F
: hexadecimal number
: hexadecimal number ve
0b011011
-0b011011
: binary number
: binary number ve
printf("\n\n
printf("\n\n
printf("\n\n
printf("\n\n
printf("\n\n
printf("\n\n
printf("\n\n
Binary: %b",0b101);
Octal: %o",017);
Scientific1: %f",1.6201e-4);
Scientific1: %g",1.6201e-4);
Scientific3: %.3g",1.6201e-4);
Scientific4: %e",1.6201e-4);
Scientific5: %.3e",1.6201e-4);