Wednesday, February 18, 2009

Use of pragma strict.

Use the pragma strict tells the compiler to generate three types of errors

  • An error for any variables used before it was declared
  • An error if your code uses symbolic references
  • An error if your code uses bare words

How to turn on Perl warnings? Why is that important?

Perl is very forgiving of strange and sometimes wrong code, which can mean hours spent searching for bugs and weird results.
Turning on warnings helps uncover common mistakes and strange places and save a lot of debugging time in the long run.
There are various ways of turning on Perl warnings:

  • For Perl one-liner, use -w option on the command line.
  • On Unix or Windows, use the -w option in the shebang line (The first # line in the script). Note: Windows Perl interpreter may not require it.
  • For other systems, choose compiler warnings, or check compiler documentation.

How to Run the Shell Script or External Unix or System Commands In Perl ?

  • Exec
  • system
  • backquotes (``)
  • Using Pipe Symbol In open

What is stack concepts In Perl ?

One of the most basic uses for an array is as stack
push | pop ==> LIFO
shift | unshift ==> FIFO

How do you find the length of an array?


  • $#array
  • Scalar(@array)
  • $length = @array ;

What is difference between "Use" and "require"

Use :

1. The method is used only for the modules(only to include .pm type file)

2. The included objects are varified at the time of compilation.

3. No Need to give file extension.

Use: only for modules, included objects are verified at the time of compilation

Require:

1. The method is used for both libraries and modules.

2. The included objects are verified at the run time.

3. Need to give file Extension.

Require : both library and modules, at the time run time


Essential Information In Perl

Perl comes with documentation as standard, including a complete set of manual pages that can
be accessed with the perldoc program,

  • use the command line for view Perl Man Pages
[sivkumar@VersionTech sivkumar] perldoc perl
return a list of the (many) standard Perl manual pages available as part of every Perl installation

  • The perldoc command can also return information on specific Perl modules

[sivkumar@VersionTech sivkumar]perldoc CGI
[sivkumar@VersionTech sivkumar]perldoc DBI

  • Type perldoc perldoc for information on using perldoc itself, and perldoc -h for a brief summary of options.
  • Function in the perlfunc page
[sivkumar@VersionTech sivkumar] perldoc -f funcname
# look up a function in the perlfunc page
perldoc -f split
perldoc -f sort
  • Display source code file
[sivkumar@VersionTech sivkumar] perldoc -m module # display source code file

perldoc -m CGI
perldoc -m DBI

  • perlfaq documentation
[sivkumar@VersionTech sivkumar] perldoc -q pattern # search the perlfaq documentation

  • Insensitive lookup
[sivkumar@VersionTech sivkumar] perldoc -i [options] # do a case insensitive lookup or search

perldoc -i cgi

Unix To Dos


  • #!/usr/bin/perl -pi
    s/\n/\r\n/;


Dos To Unix


  • perl -pi -e 's/\r\n/\n/;' Filename.pl
  • #!/usr/bin/perl -pi
    s/\r\n/\n/;