background preloader

Perl

Facebook Twitter

Reading and Writing Perl Config Files. Writing a REST Client in Perl. Skip to end of metadataGo to start of metadata This tutorial will write a Perl script which removes a user from all open reviews – this might be useful if a reviewer is no longer available, and is holding up the completed status of all their reviews. First install the REST::Client and JSON packages from CPAN – the details of doing this will depend on your platform. Icon Data::Dumper is very useful when developing Perl REST clients: Our script will retrieve a list of all open reviews, get the uncompleted reviewers for each review, and if one of these matches the user passed as a command line parameter we will complete the reviewer.

When JSON produces lists of objects, the structures produced depend on the number of items in the list. But if several reviews are returned the JSON will be: and if there are no reviews it will simply be: The toList function in the code below handles the three cases above. Search CPAN. How to contribute to CPAN. Contents Status of this document This document is mirrored on CPAN as CPAN/modules/04pause.html. Uploading A server dedicated to collect the work of perl authors is a [Perl programming] Authors Upload Server (PAUSE). Important: make sure the filename you choose contains a version number. Use one of the many CPAN Mirrors to download from.

Registering as a developer Registered developers have a unique username and a home directory in the authors/id/ tree of CPAN. If you have written a module, script, or documentation you would like to contribute to the archive, visit pause.perl.org Registration (Non-SSL version) and fill in the form. Visit PAUSE As soon as you have a password (see registering) you are enabled to use some forms to interact with the PAUSE database (Non-SSL version). If you haven't got a password yet or have forgotten it, please visit Your duties, the basics, traps Before you upload Before uploading a new module to CPAN, please carefully consider: List::MoreUtils. List::MoreUtils - Provide the stuff missing in List::Util use List::MoreUtils qw(any all none notall true false firstidx first_index lastidx last_index insert_after insert_after_string apply after after_incl before before_incl indexes firstval first_value lastval last_value each_array each_arrayref pairwise natatime mesh zip uniq minmax); List::MoreUtils provides some trivial but commonly needed functionality on lists which is not going to go into List::Util.

All of the below functions are implementable in only a couple of lines of Perl code. Using the functions from this module however should give slightly better performance as everything is implemented in C. The pure-Perl implementation of these functions only serves as a fallback in case the C portions of this module couldn't be compiled on this machine. any BLOCK LIST Returns a true value if any item in LIST meets the criterion given through BLOCK. Print "At least one value undefined" if any { ! All BLOCK LIST none BLOCK LIST Example: or. Cache::Memcached::Fast. Version 0.16. Cache::Memcahced::Fast is a Perl client for memcached, a memory cache daemon ( Module core is implemented in C and tries hard to minimize number of system calls and to avoid any key/value copying for speed. As a result, it has very low CPU consumption. API is largely compatible with Cache::Memcached, original pure Perl client, most users of the original module may start using this module by installing it and adding "::Fast" to the old name in their scripts (see "Compatibility with Cache::Memcached" below for full details). enable_compress $memd->enable_compress($enable); Enable compression when boolean $enable is true, disable when false.

Note that you can enable compression only when you set "compress_threshold" to some positive value and "compress_methods" is set. Return: none. namespace $memd->namespace; $memd->namespace($string); Without the argument return the current namespace prefix. Set Store the $value on the server under the $key. Set_multi. Functions A-Z. Perl version Preferences <div class="noscript"><p><strong>Please note: Many features of this site require JavaScript. You appear to have JavaScript disabled, or are running a non-JavaScript capable web browser. </strong></p><p> To get the best experience, please enable JavaScript or download a modern web browser such as <a href=" Explorer 8</a>, <a href=" <a href=" or <a href=" Chrome</a>.

</p></div> AUTOLOAD abs - absolute value function accept - accept an incoming socket connect alarm - schedule a SIGALRM and atan2 - arctangent of Y/X in the range -PI to PI BEGIN bind - binds an address to a socket binmode - prepare binary files for I/O bless - create an object break - break out of a "given" block hex - convert a string to a hexadecimal number. Sprintf. Perl does its own sprintf formatting: it emulates the C function sprintf(3), but doesn't use it except for floating-point numbers, and even then only standard modifiers are allowed.

Non-standard extensions in your local sprintf(3) are therefore unavailable from Perl. Unlike printf , sprintf does not do what you probably mean when you pass it an array as your first argument. The array is given scalar context, and instead of using the 0th element of the array as the format, Perl will use the count of elements in the array as the format, which is almost never useful. Finally, for backward (and we do mean "backward") compatibility, Perl permits these unnecessary but widely-supported conversions: Note that the number of exponent digits in the scientific notation produced by %e , %E , %g and %G for numbers with the modulus of the exponent less than 100 is system-dependent: it may be three or less (zero-padded as necessary).

An explicit format parameter index, such as 2$ . One or more of: So: Unpack. Splice. Tutorial. So you want to get going in a hurry? To illustrate the use of SWIG, suppose you have some C functions you want added to Tcl, Perl, Python, Java and C#. Specifically, let's say you have them in a file 'example.c' /* File : example.c */ #include <time.h> double My_variable = 3.0; int fact(int n) { if (n <= 1) return 1; else return n*fact(n-1); } int my_mod(int x, int y) { return (x%y); } char *get_time() { time_t ltime; time(&ltime); return ctime(&ltime); } Interface file Now, in order to add these files to your favorite language, you need to write an "interface file" which is the input to SWIG. An interface file for these C functions might look like this : /* example.i */ %module example %{ /* Put header files here or function declarations like below */ extern double My_variable; extern int fact(int n); extern int my_mod(int x, int y); extern char *get_time(); %} extern double My_variable; extern int fact(int n); extern int my_mod(int x, int y); extern char *get_time(); Building a Tcl module.