... continued ...
-Perl control structures:
- if (expr) {...}
unless (expr) {...}
- if (expr) {...} else {...}
- if (expr) {...} elsif {...} .. else {...}
- foreach|for var (list) {...}
- foreach|for (expr1; expr2; expr3) {...}
- while (expr) {...}
- until (expr) {...}
-useful functions/expressions:
- my - limits scope of a variable
- die - sends its argument to stderr and aborts program
- chomp - removes trailing newlines
- say - prints with a newline
- print - prints output on stdout
- open - opens a file
- sort - returns elements of an array in order
- reverse - returns elements of an array in reverse order
- $! - last system error
- @ARGV - array holding the arguments from the cmdline
- %ENV - env variables of the shell that called perl
- split - divides a string into substrings
- shift, push, pop, slice - array functions
-subroutines are distinct function blocks apart from the main program.
-subroutines can be called by other programs.
-this keeps the program structure modular.
-variables defined in the main prog are available to the subroutines.
-variables defined in the subroutine hv local scope by default.
-subs are defined by sub keyword and a name, {}
-eg: sub asub{..}
-they are called by their name and ()
-eg: asub ()
-params passed to a subroutine are listed in an array @_ and elements in @_ are $_
-cpan is the repository for perl docs, faqs and modules.
-perl modules come as tar files.
-in the module, first follow the 'readme' file.
-then create the config by running 'perl Makefile.PL'
-then run the 'make' on the Makefile just created to create the pkg.
-then run the 'make test' to test the module works.
-then run the 'make install' as root to install the module.
-post install, you can query perldoc to review the documentation.
-Perl control structures:
- if (expr) {...}
unless (expr) {...}
- if (expr) {...} else {...}
- if (expr) {...} elsif {...} .. else {...}
- foreach|for var (list) {...}
- foreach|for (expr1; expr2; expr3) {...}
- while (expr) {...}
- until (expr) {...}
-useful functions/expressions:
- my - limits scope of a variable
- die - sends its argument to stderr and aborts program
- chomp - removes trailing newlines
- say - prints with a newline
- print - prints output on stdout
- open - opens a file
- sort - returns elements of an array in order
- reverse - returns elements of an array in reverse order
- $! - last system error
- @ARGV - array holding the arguments from the cmdline
- %ENV - env variables of the shell that called perl
- split - divides a string into substrings
- shift, push, pop, slice - array functions
-subroutines are distinct function blocks apart from the main program.
-subroutines can be called by other programs.
-this keeps the program structure modular.
-variables defined in the main prog are available to the subroutines.
-variables defined in the subroutine hv local scope by default.
-subs are defined by sub keyword and a name, {}
-eg: sub asub{..}
-they are called by their name and ()
-eg: asub ()
-params passed to a subroutine are listed in an array @_ and elements in @_ are $_
-cpan is the repository for perl docs, faqs and modules.
-perl modules come as tar files.
-in the module, first follow the 'readme' file.
-then create the config by running 'perl Makefile.PL'
-then run the 'make' on the Makefile just created to create the pkg.
-then run the 'make test' to test the module works.
-then run the 'make install' as root to install the module.
-post install, you can query perldoc to review the documentation.
No comments:
Post a Comment