Showing posts with label perl. Show all posts
Showing posts with label perl. Show all posts

Tuesday, January 11, 2011

PERL Functions






Definition and Usage

If EXPR is numeric, then it demands that the script requires the specified version of Perl in order to continue. If EXPR or $_ are not numeric, it assumes that the name is the name of a library file to be included. You cannot include the same file with this function twice. The included file must return a true value as the last statement.
This differs from use in that included files effectively become additional text for the current script. Functions, variables, and other objects are not imported into the current name space, so if the specified file includes a package definition, then objects will require fully qualified names.
The specified module is searched for in the directories defined in @INC, looking for a file with the specified name and an extension of .pm.

Return Value

  • Nothing

Example

Try out following example:
#!/usr/bin/perl -w

# require to demand a particular perl version.
require 5.003;

# require to include amodule.
require Module;
Perl_Programming_Tutorial

Tags: perl, functions
Source: http://www.tutorialspoint.com/perl/perl_require.htm

Tuesday, April 27, 2010

Perl programming: system() cmd


Link ref:
String matching




Problem:

You need to use a user's input as part of a command, but you don't want to allow the user to make the shell run other commands or look at other files. If you just blindly call the system function or backticks on a single string containing a command line, the shell might be used to run the command. This would be unsafe.

Solution:
Unlike its single-argument version, the list form of the system function is safe from shell escapes. When the command's arguments involve user input from a form, never use this:

system("command $input @files"); # UNSAFE

Write it this way instead:

system("command", $input, @files); # safer

Labels