iterated
Sponsored Links
Sponsored Links
Secleted [ 0 ] software to compare
Results 1 - 15 of about 49
Iterator::Util 0.02
Iterator::Util Perl package contains essential utilities for the Iterator class. more>>
Iterator::Util Perl package contains essential utilities for the Iterator class.
SYNOPSIS
use Iterator::Util;
# Transform sequences
$iterator = imap { transformation code } $some_other_iterator;
# Filter sequences
$iterator = igrep { condition code } $some_other_iterator;
# Range of values (arithmetic sequence)
$iter = irange ($start, $end, $increment);
$iter = irange ($start, $end);
$iter = irange ($start);
# Iterate over an arbitrary list
$iter = ilist (item, item, ...);
$iter = ilist (@items);
# Iterate over an array, by reference
$iter = iarray (@array);
# Return at most $num items from an iterator
$iter = ihead ($num, $some_other_iterator);
@values = ihead ($num, $some_other_iterator);
# Append multiple iterators into one
$iter = iappend ($it1, $it2, $it3, ...);
# Apply a function to pairs of iterator values
$iter = ipairwise {code} $iter_A, $iter_B;
# Skip the first $num values of an iterator
$iter = iskip ($num, $some_other_iterator);
# Skip values from an iterator until a condition is met
$iter = iskip_until {code} $some_other_iterator;
# Mesh iterators together
$iter = imesh ($iter, $iter, ...);
$iter = izip ($iter, $iter, ...);
# Return each value of an iterator once
$iter = iuniq ($another_iterator);
This module implements many useful functions for creating and manipulating iterator objects.
An "iterator" is an object, represented as a code block that generates the "next value" of a sequence, and generally implemented as a closure. For further information, including a tutorial on using iterator objects, see the Iterator documentation.
<<lessSYNOPSIS
use Iterator::Util;
# Transform sequences
$iterator = imap { transformation code } $some_other_iterator;
# Filter sequences
$iterator = igrep { condition code } $some_other_iterator;
# Range of values (arithmetic sequence)
$iter = irange ($start, $end, $increment);
$iter = irange ($start, $end);
$iter = irange ($start);
# Iterate over an arbitrary list
$iter = ilist (item, item, ...);
$iter = ilist (@items);
# Iterate over an array, by reference
$iter = iarray (@array);
# Return at most $num items from an iterator
$iter = ihead ($num, $some_other_iterator);
@values = ihead ($num, $some_other_iterator);
# Append multiple iterators into one
$iter = iappend ($it1, $it2, $it3, ...);
# Apply a function to pairs of iterator values
$iter = ipairwise {code} $iter_A, $iter_B;
# Skip the first $num values of an iterator
$iter = iskip ($num, $some_other_iterator);
# Skip values from an iterator until a condition is met
$iter = iskip_until {code} $some_other_iterator;
# Mesh iterators together
$iter = imesh ($iter, $iter, ...);
$iter = izip ($iter, $iter, ...);
# Return each value of an iterator once
$iter = iuniq ($another_iterator);
This module implements many useful functions for creating and manipulating iterator objects.
An "iterator" is an object, represented as a code block that generates the "next value" of a sequence, and generally implemented as a closure. For further information, including a tutorial on using iterator objects, see the Iterator documentation.
Download (0.020MB)
Added: 2007-05-18 License: Perl Artistic License Price:
889 downloads
PicoStorage 0.1
PicoStorage is a lightweight structured storage software. more>>
PicoStorage allows you to store hierarhical information (similar to "files and directories") inside a single file. The functionality offered is largely equivalent to the one offered by any filesystem, or by the Structured Storage and Compound Files.
PicoStorage can efficiently handle huge numbers of small files, with very economical disk usage; it also allows you to keep open (in RAM) simultaneously a large number of files. Transaction support guarantees data integrity.
Learn more about the distinctive advantages of PicoStorage. or look at the benchmark.
The library is available on a dual-license basis: under GPL for free, and under a commercial license for use in closed-source applications.
Using
The library contains the classes File and Dir to represent files and directories. On a File you can read or write a number of bytes from a given offset, and set/get the file size. On a Dir you can create entries (either files or subdirectories), open entries, delete entries, and iterate over the directorys content.
The storage itself (i.e. the whole hierarchical structure, contained in a filesystem file) is represented by the class Storage. Using this class, you can create or open a storage, obtain the root directory of the storage, close the storage and do commit or rollback.
<<lessPicoStorage can efficiently handle huge numbers of small files, with very economical disk usage; it also allows you to keep open (in RAM) simultaneously a large number of files. Transaction support guarantees data integrity.
Learn more about the distinctive advantages of PicoStorage. or look at the benchmark.
The library is available on a dual-license basis: under GPL for free, and under a commercial license for use in closed-source applications.
Using
The library contains the classes File and Dir to represent files and directories. On a File you can read or write a number of bytes from a given offset, and set/get the file size. On a Dir you can create entries (either files or subdirectories), open entries, delete entries, and iterate over the directorys content.
The storage itself (i.e. the whole hierarchical structure, contained in a filesystem file) is represented by the class Storage. Using this class, you can create or open a storage, obtain the root directory of the storage, close the storage and do commit or rollback.
Download (0.13MB)
Added: 2005-04-13 License: GPL (GNU General Public License) Price:
1655 downloads
Array::Iterator 0.06
Array::Iterator is a simple class for iterating over Perl arrays. more>>
Array::Iterator is a simple class for iterating over Perl arrays.
SYNOPSIS
use Array::Iterator;
# create an iterator with an array
my $i = Array::Iterator->new(1 .. 100);
# create an iterator with an array reference
my $i = Array::Iterator->new(@array);
# create an iterator with a hash reference
my $i = Array::Iterator->new({ __array__ => @array });
# a base iterator example
while ($i->hasNext()) {
if ($i->peek() < 50) {
# ... do something because
# the next element is over 50
}
my $current = $i->next();
# ... do something with current
}
# shortcut style
my @accumulation;
push @accumulation => { item => $iterator->next() } while $iterator->hasNext();
# C++ ish style iterator
for (my $i = Array::Iterator->new(@array); $i->hasNext(); $i->next()) {
my $current = $i->current();
# .. do something with current
}
# common perl iterator idiom
my $current;
while ($current = $i->getNext()) {
# ... do something with $current
}
This class provides a very simple iterator interface. It is is uni-directional and can only be used once. It provides no means of reverseing or reseting the iterator. It is not recommended to alter the array during iteration, however no attempt is made to enforce this (although I will if I can find an efficient means of doing so). This class only intends to provide a clear and simple means of generic iteration, nothing more (yet).
<<lessSYNOPSIS
use Array::Iterator;
# create an iterator with an array
my $i = Array::Iterator->new(1 .. 100);
# create an iterator with an array reference
my $i = Array::Iterator->new(@array);
# create an iterator with a hash reference
my $i = Array::Iterator->new({ __array__ => @array });
# a base iterator example
while ($i->hasNext()) {
if ($i->peek() < 50) {
# ... do something because
# the next element is over 50
}
my $current = $i->next();
# ... do something with current
}
# shortcut style
my @accumulation;
push @accumulation => { item => $iterator->next() } while $iterator->hasNext();
# C++ ish style iterator
for (my $i = Array::Iterator->new(@array); $i->hasNext(); $i->next()) {
my $current = $i->current();
# .. do something with current
}
# common perl iterator idiom
my $current;
while ($current = $i->getNext()) {
# ... do something with $current
}
This class provides a very simple iterator interface. It is is uni-directional and can only be used once. It provides no means of reverseing or reseting the iterator. It is not recommended to alter the array during iteration, however no attempt is made to enforce this (although I will if I can find an efficient means of doing so). This class only intends to provide a clear and simple means of generic iteration, nothing more (yet).
Download (0.010MB)
Added: 2007-06-11 License: Perl Artistic License Price:
865 downloads
Template::FAQ 2.19
Template::FAQ contains Frequently Asked Questions about the Template Toolkit. more>>
Template::FAQ contains Frequently Asked Questions about the Template Toolkit.
Template Toolkit Language
Why doesnt [% a = b IF c %] work as expected?
Because the parser interprets it as
[% a = (b IF c) %]
Do this instead:
[% SET a = b IF c %]
If Im using TT to write out a TT template, is there a good way to escape [% and %]?
You can do this:
[% stag = "[%"
etag = "%]"
%]
and then:
[% stag; hello; etag %]
Or something like:
[% TAGS [- -] %]
[- INCLUDE foo -] # is a directive
[% INCLUDE foo %] # not a directive, just plain text, passed through
How do I iterate over a hash?
This is covered in the Template::Manual::VMethods section of the manual page. A list of all the keys that are in the hash can be obtained with the keys virtual method. You can then iterate over that list and by looking up each key in turn get the value.
[% FOREACH key = product.keys %]
[% key %] => [% product.$key %]
[% END %]
<<lessTemplate Toolkit Language
Why doesnt [% a = b IF c %] work as expected?
Because the parser interprets it as
[% a = (b IF c) %]
Do this instead:
[% SET a = b IF c %]
If Im using TT to write out a TT template, is there a good way to escape [% and %]?
You can do this:
[% stag = "[%"
etag = "%]"
%]
and then:
[% stag; hello; etag %]
Or something like:
[% TAGS [- -] %]
[- INCLUDE foo -] # is a directive
[% INCLUDE foo %] # not a directive, just plain text, passed through
How do I iterate over a hash?
This is covered in the Template::Manual::VMethods section of the manual page. A list of all the keys that are in the hash can be obtained with the keys virtual method. You can then iterate over that list and by looking up each key in turn get the value.
[% FOREACH key = product.keys %]
[% key %] => [% product.$key %]
[% END %]
Download (0.76MB)
Added: 2007-08-16 License: Perl Artistic License Price:
801 downloads
libwrapiter 1.2.0
libwrapiter is a library that provides wrappers for C++ STL style iterators. more>>
libwrapiter is a library that provides wrappers for C++ STL style iterators.
It makes it easy to define generic iterator wrappers, which remove the need to expose underlying data structures when working with classes using STL containers.
Purpose:
Consider the following massively oversimplified example. Were using the private implementation pattern or pimpl to avoid sticking too much in the header files.
myproject/myclass.hh without libwrapiter
#include < list >
namespace myproject
{
class MyClass
{
private:
///name implementation data, using the private implementation pattern
///{
struct Implementation;
Implementation * _imp;
///}
///name disallow copying and assignment
///{
MyClass(const MyClass &);
const MyClass & operator= (const MyClass &);
///}
public:
MyClass();
~MyClass();
///name iterate over our items
///{
typedef std::list ::const_iterator Iterator;
Iterator begin() const;
Iterator end() const;
///}
};
}
Enhancements:
- Headers are now split into -fwd, -decl, and -impl, allowing finer grained control to give faster compile times.
- The old, undecorated header paths are still fine if you dont need this kind of control.
- libwrapiter has a new homepage.
<<lessIt makes it easy to define generic iterator wrappers, which remove the need to expose underlying data structures when working with classes using STL containers.
Purpose:
Consider the following massively oversimplified example. Were using the private implementation pattern or pimpl to avoid sticking too much in the header files.
myproject/myclass.hh without libwrapiter
#include < list >
namespace myproject
{
class MyClass
{
private:
///name implementation data, using the private implementation pattern
///{
struct Implementation;
Implementation * _imp;
///}
///name disallow copying and assignment
///{
MyClass(const MyClass &);
const MyClass & operator= (const MyClass &);
///}
public:
MyClass();
~MyClass();
///name iterate over our items
///{
typedef std::list ::const_iterator Iterator;
Iterator begin() const;
Iterator end() const;
///}
};
}
Enhancements:
- Headers are now split into -fwd, -decl, and -impl, allowing finer grained control to give faster compile times.
- The old, undecorated header paths are still fine if you dont need this kind of control.
- libwrapiter has a new homepage.
Download (0.13MB)
Added: 2007-06-06 License: GPL (GNU General Public License) Price:
871 downloads
AtExit 2.01
AtExit is a Perl module that can perform exit processing for a program or object. more>>
AtExit is a Perl module that can perform exit processing for a program or object.
SYNOPSIS
use AtExit;
sub cleanup {
my @args = @_;
print "cleanup() executing: args = @argsn";
}
## Register subroutines to be called when this program exits
$_ = atexit(&cleanup, "This call was registered first");
print "first call to atexit() returned $_n";
$_ = atexit("cleanup", "This call was registered second");
print "second call to atexit() returned $_n";
$_ = atexit("cleanup", "This call shouldve been unregistered by rmexit");
rmexit($_) or warn "couldnt unregister exit-sub $_!";
if (@ARGV == 0) {
## Register subroutines to be called when this lexical scope is exited
my $scope1 = AtExit->new( &cleanup, "Scope 1, Callback 1" );
{
## Do the same for this nested scope
my $scope2 = AtExit->new;
$_ = $scope2->atexit( &cleanup, "Scope 2, Callback 1" );
$scope1->atexit( &cleanup, "Scope 1, Callback 2");
$scope2->atexit( &cleanup, "Scope 2, Callback 2" );
$scope2->rmexit($_) or warn "couldnt unregister exit-sub $_!";
print "*** Leaving Scope 2 ***n";
}
print "*** Finished Scope 2 ***n";
print "*** Leaving Scope 1 ***n";
}
print "*** Finished Scope 1 ***n" if (@ARGV == 0);
END {
print "*** Now performing program-exit processing ***n";
}
The AtExit module provides ANSI-C style exit processing modeled after the atexit function in the standard C library (see atexit(3C)). Various exit processing routines may be registered by calling atexit and passing it the desired subroutine along with any desired arguments. Then, at program-exit time, the subroutines registered with atexit are invoked with their given arguments in the reverse order of registration (last one registered is invoked first). Registering the same subroutine more than once will cause that subroutine to be invoked once for each registration.
An AtExit object can be created in any scope. When invoked as a function, atexit registers callbacks to be executed at program-exit time. But when invoked as an object-method (using the $object->method_name syntax), callbacks registered with an AtExit object are executed at object-destruction time! The rules for order of execution of the registered subroutines are the same for objects during object-destruction, as for the program during program-termination.
The atexit function/method should be passed a subroutine name or reference, optionally followed by the list of arguments with which to invoke it at program/object exit time. Anonymous subroutine references passed to atexit act as "closures" (which are described in perlref). If a subroutine name is specified (as opposed to a subroutine reference) then, unless the subroutine name has an explicit package prefix, it is assumed to be the name of a subroutine in the callers current package. A reference to the specified subroutine is obtained, and, if invocation arguments were specified, it is "wrapped up" in a closure which invokes the subroutine with the specified arguments. The resulting subroutine reference is added to the front of the list of exit-handling subroutines for the program (atexit) or the AtExit object ($exitObject->atexit) and the reference is then returned to the caller (just in case you might want to unregister it later using rmexit. If the given subroutine could not be registered, then the value zero is returned.
The rmexit function/method should be passed one or more subroutine references, each of which was returned by a previous call to atexit. For each argument given, rmexit will look in the list of exit-handling subroutines for the program (rmexit) or the AtExit object ($exitObject->rmexit) and remove the first matching entry from the list. If no arguments are given, then all program or object exit-handlers are unregistered! The value returned will be the number of subroutines that were successfully unregistered.
At object destruction time, the DESTROY{} subroutine in the AtExit module iterates over the subroutine references in the AtExit object and invokes each one in turn (each subroutine is removed from the front of the queue immediately before it is invoked). At program-exit time, the END{} block in the AtExit module iterates over the subroutines in the array returned by the exit_subs method and invokes each one in turn (each subroutine is removed from the front of the queue immediately before it is invoked). Note that in both cases (program-exit, and object-destruction) the subroutines in this queue are invoked in first-to-last order (the reverse order in which they were registered with atexit).
<<lessSYNOPSIS
use AtExit;
sub cleanup {
my @args = @_;
print "cleanup() executing: args = @argsn";
}
## Register subroutines to be called when this program exits
$_ = atexit(&cleanup, "This call was registered first");
print "first call to atexit() returned $_n";
$_ = atexit("cleanup", "This call was registered second");
print "second call to atexit() returned $_n";
$_ = atexit("cleanup", "This call shouldve been unregistered by rmexit");
rmexit($_) or warn "couldnt unregister exit-sub $_!";
if (@ARGV == 0) {
## Register subroutines to be called when this lexical scope is exited
my $scope1 = AtExit->new( &cleanup, "Scope 1, Callback 1" );
{
## Do the same for this nested scope
my $scope2 = AtExit->new;
$_ = $scope2->atexit( &cleanup, "Scope 2, Callback 1" );
$scope1->atexit( &cleanup, "Scope 1, Callback 2");
$scope2->atexit( &cleanup, "Scope 2, Callback 2" );
$scope2->rmexit($_) or warn "couldnt unregister exit-sub $_!";
print "*** Leaving Scope 2 ***n";
}
print "*** Finished Scope 2 ***n";
print "*** Leaving Scope 1 ***n";
}
print "*** Finished Scope 1 ***n" if (@ARGV == 0);
END {
print "*** Now performing program-exit processing ***n";
}
The AtExit module provides ANSI-C style exit processing modeled after the atexit function in the standard C library (see atexit(3C)). Various exit processing routines may be registered by calling atexit and passing it the desired subroutine along with any desired arguments. Then, at program-exit time, the subroutines registered with atexit are invoked with their given arguments in the reverse order of registration (last one registered is invoked first). Registering the same subroutine more than once will cause that subroutine to be invoked once for each registration.
An AtExit object can be created in any scope. When invoked as a function, atexit registers callbacks to be executed at program-exit time. But when invoked as an object-method (using the $object->method_name syntax), callbacks registered with an AtExit object are executed at object-destruction time! The rules for order of execution of the registered subroutines are the same for objects during object-destruction, as for the program during program-termination.
The atexit function/method should be passed a subroutine name or reference, optionally followed by the list of arguments with which to invoke it at program/object exit time. Anonymous subroutine references passed to atexit act as "closures" (which are described in perlref). If a subroutine name is specified (as opposed to a subroutine reference) then, unless the subroutine name has an explicit package prefix, it is assumed to be the name of a subroutine in the callers current package. A reference to the specified subroutine is obtained, and, if invocation arguments were specified, it is "wrapped up" in a closure which invokes the subroutine with the specified arguments. The resulting subroutine reference is added to the front of the list of exit-handling subroutines for the program (atexit) or the AtExit object ($exitObject->atexit) and the reference is then returned to the caller (just in case you might want to unregister it later using rmexit. If the given subroutine could not be registered, then the value zero is returned.
The rmexit function/method should be passed one or more subroutine references, each of which was returned by a previous call to atexit. For each argument given, rmexit will look in the list of exit-handling subroutines for the program (rmexit) or the AtExit object ($exitObject->rmexit) and remove the first matching entry from the list. If no arguments are given, then all program or object exit-handlers are unregistered! The value returned will be the number of subroutines that were successfully unregistered.
At object destruction time, the DESTROY{} subroutine in the AtExit module iterates over the subroutine references in the AtExit object and invokes each one in turn (each subroutine is removed from the front of the queue immediately before it is invoked). At program-exit time, the END{} block in the AtExit module iterates over the subroutines in the array returned by the exit_subs method and invokes each one in turn (each subroutine is removed from the front of the queue immediately before it is invoked). Note that in both cases (program-exit, and object-destruction) the subroutines in this queue are invoked in first-to-last order (the reverse order in which they were registered with atexit).
Download (0.008MB)
Added: 2007-05-23 License: Perl Artistic License Price:
884 downloads
ZDraw
ZDraw is a fairly basic drawing applet used to demonstrate the concept of persistence in a drawing applet. more>>
ZDraw is a fairly basic drawing applet used to demonstrate the concept of persistence in a drawing applet. What do I mean by persistence? Well, take most of the "demo" drawing applets available on the net. If you put the applet into the background, resize it, or partially/fully cover it with another window, then the "hidden" portion of the applet loses any drawings that were made.
A simple (and rudimentary) solution to this can be easily implemented using a Vector and creating a new object class LineObject within which we can store the start and end points of each line, together with its colour. Then, when we can override public void paint( Graphics g ) and insert some code that iterates through each element of the vector, repainting each line segment. This way, everytime the applet redraws itself, all of the lines will be repainted, and thus will not be lost!
<<lessA simple (and rudimentary) solution to this can be easily implemented using a Vector and creating a new object class LineObject within which we can store the start and end points of each line, together with its colour. Then, when we can override public void paint( Graphics g ) and insert some code that iterates through each element of the vector, repainting each line segment. This way, everytime the applet redraws itself, all of the lines will be repainted, and thus will not be lost!
Download (0.003MB)
Added: 2007-03-12 License: GPL (GNU General Public License) Price:
956 downloads
File::Find::Parallel 0.0.4
File::Find::Parallel allows you to traverse a number of similar directories in parallel. more>>
File::Find::Parallel allows you to traverse a number of similar directories in parallel.
SYNOPSIS
use File::Find::Parallel;
my $ffp = File::Find::Parallel->new( qw( /foo /bar ) );
print "Union:n";
my $union = $ffp->any_iterator
print " $_n" while $_ = $union->();
print "Intersection:n";
my $inter = $ffp->all_iterator
print " $_n" while $_ = $inter->();
File::Find is the ideal tool for quickly scanning a single directory. But sometimes its nice to be able to perform operations on multiple similar directories in parallel. Perhaps you need to compare the contents of two directories or convert files that are shared in more than one directory into hard links.
This module manufactures iterators that visit each file and directory in either the union or the intersection of a number of directories. Hmm. What does that mean?
Given two directory trees like this
foo
foo/a
foo/b/c
foo/d
bar
bar/a
bar/b
bar/e
you can choose to work with the intersection of the two directory structures:
.
./a
./b
That is the subdirectories and files that the foo and bar share.
Alternately you can work with the union of the two directory structures:
.
./a
./b
./b/c
./d
./e
Still not clear? Well, if you wanted to do a recursive diff on the two directories youd iterate their union so you could report files that were present in foo but missing from bar and vice-versa.
If, on the other hand you wanted to scan the directories and find all the files that are common to all of them youd iterate their intersection and receive only files and directories that were present in all the directories being scanned.
The any_iterator and all_iterator are built on a more general purpose method: want_iterator. If, for example, you want to make links between files that are found in more than one directory you might get your iterator like this:
my $iter = $ffp->want_iterator( 2 );
The apparently magic 2 reflects the fact that if youre going to be making links you need at least two files. No matter how many directories you are iterating over in parallel you will only see files and directories that appear in at least two of those directories.
File::Find::Parallel can scan any number of directories at the same time. Heres an example (on Unix systems) that returns the list of all files and directories that are contained in all home directories.
use File::Glob :glob;
use File::Find::Parallel;
my $find = File::Find::Parallel->new( bsd_glob( /home/* ) );
my @common = ( );
my $iter = $find->all_iterator;
while ( defined my $obj = $iter->() ) {
push @common, $obj;
}
print "The following files are common to ",
"all directories below /home :n";
print " $_n" for @common;
For a complete concrete example of its use see lncopies in the bin subdirectory of this distribution.
Iterators
The iterator returned by any_iterator, all_iterator or want_iterator is a code reference. Call it to get the next file or directory. When all files and directories have been returned the iterator will return undef.
Once created an iterator is independent of the File::Find::Parallel object that created it. If the object goes out of scope and is destroyed during the life of the iterator it will still function normally.
You may have many active iterators for a single File::Find::Parallel object at any time.
<<lessSYNOPSIS
use File::Find::Parallel;
my $ffp = File::Find::Parallel->new( qw( /foo /bar ) );
print "Union:n";
my $union = $ffp->any_iterator
print " $_n" while $_ = $union->();
print "Intersection:n";
my $inter = $ffp->all_iterator
print " $_n" while $_ = $inter->();
File::Find is the ideal tool for quickly scanning a single directory. But sometimes its nice to be able to perform operations on multiple similar directories in parallel. Perhaps you need to compare the contents of two directories or convert files that are shared in more than one directory into hard links.
This module manufactures iterators that visit each file and directory in either the union or the intersection of a number of directories. Hmm. What does that mean?
Given two directory trees like this
foo
foo/a
foo/b/c
foo/d
bar
bar/a
bar/b
bar/e
you can choose to work with the intersection of the two directory structures:
.
./a
./b
That is the subdirectories and files that the foo and bar share.
Alternately you can work with the union of the two directory structures:
.
./a
./b
./b/c
./d
./e
Still not clear? Well, if you wanted to do a recursive diff on the two directories youd iterate their union so you could report files that were present in foo but missing from bar and vice-versa.
If, on the other hand you wanted to scan the directories and find all the files that are common to all of them youd iterate their intersection and receive only files and directories that were present in all the directories being scanned.
The any_iterator and all_iterator are built on a more general purpose method: want_iterator. If, for example, you want to make links between files that are found in more than one directory you might get your iterator like this:
my $iter = $ffp->want_iterator( 2 );
The apparently magic 2 reflects the fact that if youre going to be making links you need at least two files. No matter how many directories you are iterating over in parallel you will only see files and directories that appear in at least two of those directories.
File::Find::Parallel can scan any number of directories at the same time. Heres an example (on Unix systems) that returns the list of all files and directories that are contained in all home directories.
use File::Glob :glob;
use File::Find::Parallel;
my $find = File::Find::Parallel->new( bsd_glob( /home/* ) );
my @common = ( );
my $iter = $find->all_iterator;
while ( defined my $obj = $iter->() ) {
push @common, $obj;
}
print "The following files are common to ",
"all directories below /home :n";
print " $_n" for @common;
For a complete concrete example of its use see lncopies in the bin subdirectory of this distribution.
Iterators
The iterator returned by any_iterator, all_iterator or want_iterator is a code reference. Call it to get the next file or directory. When all files and directories have been returned the iterator will return undef.
Once created an iterator is independent of the File::Find::Parallel object that created it. If the object goes out of scope and is destroyed during the life of the iterator it will still function normally.
You may have many active iterators for a single File::Find::Parallel object at any time.
Download (0.009MB)
Added: 2007-07-07 License: Perl Artistic License Price:
840 downloads
List::MRU 0.04
List::MRU is a Perl module that implements a simple fixed-size MRU-ordered list. more>>
List::MRU is a Perl module that implements a simple fixed-size MRU-ordered list.
SYNOPSIS
use List::MRU;
# Constructor
$lm = List::MRU->new(max => 20);
# Constructor with explicit eq subroutine for obj equality tests
$lm = List::MRU->new(max => 20, eq => sub {
$_[0]->stringify eq $_[1]->stringify
});
# Constructor using explicit UUIDs
$lm - List::MRU->new(max => 5, uuid => 1);
# Add item, moving to head of list if already exists
$lm->add($item);
# Add item, moving to head of list if $uuid matches or object already exists
$lm->add($item, $uuid);
# Iterate in most-recently-added order
for $item ($lm->list) {
print "$itemn";
}
# each-style iteration
while (($item, $uuid) = $lm->each) {
print "$item, $uuidn";
}
# Item deletion
$lm->delete($item);
$lm->delete(uuid => $uuid);
# Accessors
$max = $lm->max; # max items in list
$count = $lm->count; # current items in list
Perl module implementing a simple fixed-size most-recently-used- (MRU)-ordered list of values/objects. Well, really its a most- recently-added list - items added to the list are just promoted to the front of the list if they already exist, otherwise they are added there.
Works fine with with non-scalar items, but you will need to supply an explicit eq subroutine to the constructor to handle testing for the same object (or alternatively have overloaded the eq operator for your object).
List::MRU also supports having explicit UUIDs attached to items, allowing List::MRU items to be modified, instead of a change just creating a new entry.
<<lessSYNOPSIS
use List::MRU;
# Constructor
$lm = List::MRU->new(max => 20);
# Constructor with explicit eq subroutine for obj equality tests
$lm = List::MRU->new(max => 20, eq => sub {
$_[0]->stringify eq $_[1]->stringify
});
# Constructor using explicit UUIDs
$lm - List::MRU->new(max => 5, uuid => 1);
# Add item, moving to head of list if already exists
$lm->add($item);
# Add item, moving to head of list if $uuid matches or object already exists
$lm->add($item, $uuid);
# Iterate in most-recently-added order
for $item ($lm->list) {
print "$itemn";
}
# each-style iteration
while (($item, $uuid) = $lm->each) {
print "$item, $uuidn";
}
# Item deletion
$lm->delete($item);
$lm->delete(uuid => $uuid);
# Accessors
$max = $lm->max; # max items in list
$count = $lm->count; # current items in list
Perl module implementing a simple fixed-size most-recently-used- (MRU)-ordered list of values/objects. Well, really its a most- recently-added list - items added to the list are just promoted to the front of the list if they already exist, otherwise they are added there.
Works fine with with non-scalar items, but you will need to supply an explicit eq subroutine to the constructor to handle testing for the same object (or alternatively have overloaded the eq operator for your object).
List::MRU also supports having explicit UUIDs attached to items, allowing List::MRU items to be modified, instead of a change just creating a new entry.
Download (0.004MB)
Added: 2007-05-18 License: Perl Artistic License Price:
889 downloads
PTM 0.5.0 Beta
PTM is a Perl/HTML hybrid language, written entirely in Perl, and similar to PHP in tag syntax. more>>
PTM is a Perl/HTML hybrid. An inline development language for those that need a bit more power behind the scenes.
But more than that, it allows developers to harness Perls ability to manipulate strings of text and iterate loops many times faster than other languages on the market without the need to sacrifice development time to complex print, split, and join statements.
Additionally, PTM wraps many variables common to PHP to ease the transition between PTM and PHP when switching back and forth.
PTM was not created to replace PHP or ASP. PTM project was designed to be a complement to them. Where one fails another picks up the slack. In the world of dynamic design we need all the tools in our toolbox to get the job done. PTM is the raw power tool youve been missing.
Enhancements:
- A few functions flagged by the testers have been fixed or have had minor changes in functionality made to them, and there are two major security enhancements that have been put into place.
- A couple new base functionality functions have been added.
- A new module (RSS20) has been added that allows for simple node-based parsing of RSS 2.0 compatible XML feeds both over the Internet and stored in local files.
- The .htaccess file has been shortened to provide less overhead in Standalone/Emulation installation mode, and the installation process has been simplified.
<<lessBut more than that, it allows developers to harness Perls ability to manipulate strings of text and iterate loops many times faster than other languages on the market without the need to sacrifice development time to complex print, split, and join statements.
Additionally, PTM wraps many variables common to PHP to ease the transition between PTM and PHP when switching back and forth.
PTM was not created to replace PHP or ASP. PTM project was designed to be a complement to them. Where one fails another picks up the slack. In the world of dynamic design we need all the tools in our toolbox to get the job done. PTM is the raw power tool youve been missing.
Enhancements:
- A few functions flagged by the testers have been fixed or have had minor changes in functionality made to them, and there are two major security enhancements that have been put into place.
- A couple new base functionality functions have been added.
- A new module (RSS20) has been added that allows for simple node-based parsing of RSS 2.0 compatible XML feeds both over the Internet and stored in local files.
- The .htaccess file has been shortened to provide less overhead in Standalone/Emulation installation mode, and the installation process has been simplified.
Download (0.035MB)
Added: 2005-12-19 License: GPL (GNU General Public License) Price:
1404 downloads
Time::Skew 0.1
Time::Skew is a Perl module that computes local clock skew with respect to a remote clock. more>>
Time::Skew is a Perl module that computes local clock skew with respect to a remote clock.
SYNOPISI
use Time::Skew
# Init Convex Hull and timing data
my $hull=[];
my $result={};
# Iterate data point introduction
Time::Skew::convexhull($result,$datapoint,$hull);
This module supports the computation of the skew between two clocks: the (relative) skew is the speed with which two clocks diverge. For instance, if yesterday two clocks, at the same time, showed respectively 10:00 and 10:05, while today when the former shows 10:00 the latter shows 10:04, we say that their relative skew is 1 minute/24 hours, roughly 7E-4.
The module contains one single subroutine, which accepts as input a pair of timestamps, associated to a message from host A to host B: the timestamps correspond to the time when the message was sent, and to the time when message is received. Each timestamp reflects the value of the local clock where the operation takes place: the clock of host A for the send, the clock of B for the receive.
Please note that the module does _not_ contain any message exchange facility, but only the mathematics needed to perform the skew approximation, once timestamps are known.
The subroutine takes as argument:
a reference to a hash where values related to the timing of the network path from A to B;
a 2-elems array (a data point in the sequel) containing the timestamp of the receive event, and the differece between the send timestamp and the receive timestamp for one message;
a stack containing some data points, those that form the convex hull.
The usage is very simple, and is illustrated by the following example:
#!/usr/bin/perl -w
use strict;
use Time::Skew;
# Initialize data
my $hull=[];
my $result={};
while ( 1 ) {
# Exchange message and acquire a new data point
my $datapoint = acquire();
# Call the convexhull subroutine
Time::Skew::convexhull($result,$datapoint,$hull);
# After first message some results are still undefined
( defined $result->{skewjitter} ) || next;
# here you can use the results
};
}
The data returned in the "result" hash is the following:
result->{skew} the clock skew;
result->{skewjitter} the variance of the skew estimate, used to estimate convergence;
result->{jitter} difference between the current delay and the previous delay;
result->{delay} the communication delay, decremented by a constant (yet unknown) value, used to compute communication jitter;
result->{elems} the number of data points in the convex hull;
result->{select} the index of the data point in the convex hull used to compute the skew;
result->{itimestamp} the timestamp, first element in the data point just passed to the subroutine;
result->{delta} the timestamp difference, second element in the data point just passed to the subroutine;
The data returned in the "hull" stack is a series of data points, selected from those passed to successive calls of the subroutine. The number of data points in the "hull" stack usually does not exceed 20 units.
The algorithm is very fast: each call consists in scanning at most all data points in the "hull" stack, performing simple arithmetic operations for each element.
The algorithm must be fed with a sequence of data points before returning significant results. The accuracy of the estimate keeps growing while new data points are passed to the subroutine. A rough rule of thumb to evaluate estimate accuracy is to observe the skew jitter, and assume it corresponds to the skew estimate accuracy. Paths with quite regular communication delay (small jitter) converge faster.
<<lessSYNOPISI
use Time::Skew
# Init Convex Hull and timing data
my $hull=[];
my $result={};
# Iterate data point introduction
Time::Skew::convexhull($result,$datapoint,$hull);
This module supports the computation of the skew between two clocks: the (relative) skew is the speed with which two clocks diverge. For instance, if yesterday two clocks, at the same time, showed respectively 10:00 and 10:05, while today when the former shows 10:00 the latter shows 10:04, we say that their relative skew is 1 minute/24 hours, roughly 7E-4.
The module contains one single subroutine, which accepts as input a pair of timestamps, associated to a message from host A to host B: the timestamps correspond to the time when the message was sent, and to the time when message is received. Each timestamp reflects the value of the local clock where the operation takes place: the clock of host A for the send, the clock of B for the receive.
Please note that the module does _not_ contain any message exchange facility, but only the mathematics needed to perform the skew approximation, once timestamps are known.
The subroutine takes as argument:
a reference to a hash where values related to the timing of the network path from A to B;
a 2-elems array (a data point in the sequel) containing the timestamp of the receive event, and the differece between the send timestamp and the receive timestamp for one message;
a stack containing some data points, those that form the convex hull.
The usage is very simple, and is illustrated by the following example:
#!/usr/bin/perl -w
use strict;
use Time::Skew;
# Initialize data
my $hull=[];
my $result={};
while ( 1 ) {
# Exchange message and acquire a new data point
my $datapoint = acquire();
# Call the convexhull subroutine
Time::Skew::convexhull($result,$datapoint,$hull);
# After first message some results are still undefined
( defined $result->{skewjitter} ) || next;
# here you can use the results
};
}
The data returned in the "result" hash is the following:
result->{skew} the clock skew;
result->{skewjitter} the variance of the skew estimate, used to estimate convergence;
result->{jitter} difference between the current delay and the previous delay;
result->{delay} the communication delay, decremented by a constant (yet unknown) value, used to compute communication jitter;
result->{elems} the number of data points in the convex hull;
result->{select} the index of the data point in the convex hull used to compute the skew;
result->{itimestamp} the timestamp, first element in the data point just passed to the subroutine;
result->{delta} the timestamp difference, second element in the data point just passed to the subroutine;
The data returned in the "hull" stack is a series of data points, selected from those passed to successive calls of the subroutine. The number of data points in the "hull" stack usually does not exceed 20 units.
The algorithm is very fast: each call consists in scanning at most all data points in the "hull" stack, performing simple arithmetic operations for each element.
The algorithm must be fed with a sequence of data points before returning significant results. The accuracy of the estimate keeps growing while new data points are passed to the subroutine. A rough rule of thumb to evaluate estimate accuracy is to observe the skew jitter, and assume it corresponds to the skew estimate accuracy. Paths with quite regular communication delay (small jitter) converge faster.
Download (0.044MB)
Added: 2007-04-10 License: Perl Artistic License Price:
927 downloads
Set::Array 0.14
Set::Array Perl module contains arrays as objects with lots of handy methods and support for method chaining. more>>
Set::Array Perl module contains arrays as objects with lots of handy methods (including Set comparisons) and support for method chaining.
SYNOPSIS
my $sao1 = Set::Array->new(1,2,4,"hello",undef);
my $sao2 = Set::Array->new(qw(a b c a b c));
print $sao1->length; # prints 5
$sao2->unique->length->print; # prints 3
Set::Array allows you to create arrays as objects and use OO-style methods on them. Many convenient methods are provided here that appear in the FAQs, the Perl Cookbook or posts from comp.lang.perl.misc. In addition, there are Set methods with corresponding (overloaded) operators for the purpose of Set comparison, i.e. +, ==, etc.
The purpose is to provide built-in methods for operations that people are always asking how to do, and which already exist in languages like Ruby. This should (hopefully) improve code readability and/or maintainability. The other advantage to this module is method-chaining by which any number of methods may be called on a single object in a single statement.
OBJECT BEHAVIOR
The exact behavior of the methods depends largely on the calling context.
Here are the rules:
* If a method is called in void context, the object itself is modified.
* If the method called is not the last method in a chain (i.e. its called in object context), the object itself is modified by that method regardless of the final context or method call.
* If a method is called in list or scalar context, a list or list refererence is returned, respectively. The object itself is NOT modified.
Heres a quick example:
my $sao = Set::Array->new(1,2,3,2,3);
my @uniq = $sao->unique(); # Object unmodified. @uniq contains 3 values.
$sao->unique(); # Object modified, now contains 3 values
Here are the exceptions:
* Methods that report a value, such as boolean methods like exists() or other methods such as at() or as_hash(), never modify the object.
* The methods clear(), delete(), delete_at(), and splice will always modify the object. It seemed much too counterintuitive to call these methods in any context without actually deleting/clearing/substituting the items!
* The methods shift() and pop() will modify the object AND return the value that was shifted or popped from the array. Again, it seemed much too counterintuitive for something like $val = $sao->shift to return a value while leaving the objects list unchanged. If you really want the first or last value without modifying the object, you can always use the first() or last() method, respectively.
* The join() method always returns a string and is really meant for use in conjunction with the print() method.
BOOLEAN METHODS
exists(val) - Returns 1 if val exists within the array, 0 otherwise. If no value (or undef) is passed, then this method will test for the existence of undefined values within the array.
is_empty() - Returns 1 if the array is empty, 0 otherwise. Empty is defined as having a length of 0.
STANDARD METHODS
at(index) - Returns the item at the given index (or undef). A negative index may be used to count from the end of the array. If no value (or undef) is specified, it will look for the first item that is not defined.
clear() - Empties the array (i.e. length becomes 0). You may pass a 1 to this method to set each element of the array to undef rather than truly empty it.
compact() - Removes undefined elements from the array.
count(?val?) - Returns the number of instances of val within the array. If val is not specified (or is undef), the method will return the number of undefined values within the array.
delete(list) - Deletes all items within list from the array that match. This method will crash if list is not defined. If your goal is to delete undefined values from your object, use the compact() method instead.
delete_at(index, ?index?) - Deletes the item at the specified index. If a second index is specified, a range of items is deleted. You may use -1 or the string end to refer to the last element of the array.
duplicates - Returns a list of N-1 elements for each element N in the set. For example, if you have set "X X Y Y Y", this method would return a the list "X Y Y".
fill(val,?start?,?length?) - Sets the selected elements of the array (which may be the entire array) to val. The default value for start is 0. If length is not specified the entire array, however long it may be at the time of the call, will be filled. Alternatively, a quoted integer range may be used.
e.g. $sao->fill(x,3-5);
The array length/size may not be expanded with this call - it is only meant to fill in already-existing elements.
first() - Returns the first element of the array (or undef).
flatten() - Causes a one-dimensional flattening of the array, recursively. That is, for every element that is an array (or hash, or a ref to either an array or hash), extract its elements into the array.
e.g. my $sa = Set::Array->new([1,3,2],{one=>a,two=>b},x,y,z);
$sao->flatten->join(,)->print; # prints "1,3,2,one,a,two,b,x,y,z"
foreach(sub ref) - Iterates over an array, executing the subroutine for each element in the array. If you wish to modify or otherwise act directly on the contents of the array, use $_ within your sub reference.
e.g. To increment all elements in the array by one...
$sao->foreach(sub{ ++$_ });
get - Alias for the indices() method.
index(val) - Returns the index of the first element of the array object that contains val. Returns undef if no value is found.
Note that there is no dereferencing here so if youre looking for an item nested within a ref, use the flatten method first.
indices(val1,?val2?, ?val...?) - Returns an array consisting of the elements at the specified indices or undef if the element is out of range.
A range may also be used. It must be a quoted string in 0..3 format.
join(?char?) - Joins the individual elements of the list into a single string with the elements separated by the value of char. Useful in conjunction with the print() method. If no character is specified, then char defaults to a comma.
e.g. $sao->join(-)->print;
last() - Returns the last element of the array (or undef).
length() - Returns the number of elements within the array.
max() - Returns the maximum value of an array. No effort is made to check for non-numeric data.
pack(template) - Packs the contents of the array into a string (in scalar context) or a single array element (in object or void context).
pop() - Removes the last element from the array. Returns the popped element.
print(?1?) - Prints the contents of the array. If a 1 is provided as an argument, the output will automatically be terminated with a newline.
This also doubles as a contents method, if you just want to make a copy of the array, e.g. my @copy = $sao->print;
Can be called in void or list context, e.g.
$sao->print(); # or... print "Contents of array are: ", $sao->print();
push(list) - Adds list to the end of the array, where list is either a scalar value or a list. Returns an array or array reference in list or scalar context, respectively. Note that it does not return the length in scalar context. Use the length method for that.
reverse() - Reverses the order of the contents of the array.
rindex(val) - Similar to the index() method, except that it returns the index of the last val found within the array.
set(index,value) - Sets the element at index to value, replacing whatever may have already been there.
shift() - Shifts the first element of the array and returns the shifted element.
sort(?coderef?) - Sorts the contents of the array in alphabetical order, or in the order specified by the optional coderef. Use your standard $a and $b variables within your calling program, e.g:
my $sao = Set::Array->new( { name => Berger, salary => 20000 }, { name => Berger, salary => 15000 }, { name => Vera, salary => 25000 }, );
my $subref = sub{ $b->{name} cmp $a->{name} || $b->{salary} $a->{salary} };
$sao14->sort($subref)->flatten->join->print(1);
splice(?offset?,?length?,?list?) - Splice the array starting at position offset up to length elements, and replace them with list. If no list is provided, all elements are deleted. If length is omitted, everything from offset onward is removed.
Returns an array or array ref in list or scalar context, respectively. This method always modifies the object, regardless of context. If your goal was to grab a range of values without modifying the object, use the indices method instead.
unique() - Removes/returns non-unique elements from the list.
unshift(list) - Prepends a scalar or list to array. Note that this method returns an array or array reference in list or scalar context, respectively. It does not return the length of the array in scalar context. Use the length method for that.
ODDBALL METHODS
as_hash() - Returns a hash based on the current array, with each even numbered element (including 0) serving as the key, and each odd element serving as the value. This can be switched by using the key_order option and setting it to odd, in which case the even values serve as the values, and the odd elements serve as the keys. The default is even.
Of course, if you dont care about insertion order, you could just as well do something like, $sao-reverse->as_hash;>
Carp::croaks if the array contains an odd number of elements. This method does not actually modify the object itself in any way. It just returns a plain hash in list context or a hash reference in scalar context. The reference is not blessed, therefore if this method is called as part of a chain, it must be the last method called.
impose(?append/prepend?,string) - Appends or prepends the specified string to each element in the array. Specify the method by using either the keyword append or prepend. The default is append.
randomize() - Randomizes the order of the elements within the array.
rotate(direction) - Moves the last item of the list to the front and shifts all other elements one to the right, or vice-versa, depending on what you pass as the direction - ftol (first to last) or ltof (last to first). The default is ltof.
e.g. my $sao = Set::Array->new(1,2,3);
$sao->rotate(); # order is now 3,1,2
$sao->rotate(ftol); # order is back to 1,2,3
<<lessSYNOPSIS
my $sao1 = Set::Array->new(1,2,4,"hello",undef);
my $sao2 = Set::Array->new(qw(a b c a b c));
print $sao1->length; # prints 5
$sao2->unique->length->print; # prints 3
Set::Array allows you to create arrays as objects and use OO-style methods on them. Many convenient methods are provided here that appear in the FAQs, the Perl Cookbook or posts from comp.lang.perl.misc. In addition, there are Set methods with corresponding (overloaded) operators for the purpose of Set comparison, i.e. +, ==, etc.
The purpose is to provide built-in methods for operations that people are always asking how to do, and which already exist in languages like Ruby. This should (hopefully) improve code readability and/or maintainability. The other advantage to this module is method-chaining by which any number of methods may be called on a single object in a single statement.
OBJECT BEHAVIOR
The exact behavior of the methods depends largely on the calling context.
Here are the rules:
* If a method is called in void context, the object itself is modified.
* If the method called is not the last method in a chain (i.e. its called in object context), the object itself is modified by that method regardless of the final context or method call.
* If a method is called in list or scalar context, a list or list refererence is returned, respectively. The object itself is NOT modified.
Heres a quick example:
my $sao = Set::Array->new(1,2,3,2,3);
my @uniq = $sao->unique(); # Object unmodified. @uniq contains 3 values.
$sao->unique(); # Object modified, now contains 3 values
Here are the exceptions:
* Methods that report a value, such as boolean methods like exists() or other methods such as at() or as_hash(), never modify the object.
* The methods clear(), delete(), delete_at(), and splice will always modify the object. It seemed much too counterintuitive to call these methods in any context without actually deleting/clearing/substituting the items!
* The methods shift() and pop() will modify the object AND return the value that was shifted or popped from the array. Again, it seemed much too counterintuitive for something like $val = $sao->shift to return a value while leaving the objects list unchanged. If you really want the first or last value without modifying the object, you can always use the first() or last() method, respectively.
* The join() method always returns a string and is really meant for use in conjunction with the print() method.
BOOLEAN METHODS
exists(val) - Returns 1 if val exists within the array, 0 otherwise. If no value (or undef) is passed, then this method will test for the existence of undefined values within the array.
is_empty() - Returns 1 if the array is empty, 0 otherwise. Empty is defined as having a length of 0.
STANDARD METHODS
at(index) - Returns the item at the given index (or undef). A negative index may be used to count from the end of the array. If no value (or undef) is specified, it will look for the first item that is not defined.
clear() - Empties the array (i.e. length becomes 0). You may pass a 1 to this method to set each element of the array to undef rather than truly empty it.
compact() - Removes undefined elements from the array.
count(?val?) - Returns the number of instances of val within the array. If val is not specified (or is undef), the method will return the number of undefined values within the array.
delete(list) - Deletes all items within list from the array that match. This method will crash if list is not defined. If your goal is to delete undefined values from your object, use the compact() method instead.
delete_at(index, ?index?) - Deletes the item at the specified index. If a second index is specified, a range of items is deleted. You may use -1 or the string end to refer to the last element of the array.
duplicates - Returns a list of N-1 elements for each element N in the set. For example, if you have set "X X Y Y Y", this method would return a the list "X Y Y".
fill(val,?start?,?length?) - Sets the selected elements of the array (which may be the entire array) to val. The default value for start is 0. If length is not specified the entire array, however long it may be at the time of the call, will be filled. Alternatively, a quoted integer range may be used.
e.g. $sao->fill(x,3-5);
The array length/size may not be expanded with this call - it is only meant to fill in already-existing elements.
first() - Returns the first element of the array (or undef).
flatten() - Causes a one-dimensional flattening of the array, recursively. That is, for every element that is an array (or hash, or a ref to either an array or hash), extract its elements into the array.
e.g. my $sa = Set::Array->new([1,3,2],{one=>a,two=>b},x,y,z);
$sao->flatten->join(,)->print; # prints "1,3,2,one,a,two,b,x,y,z"
foreach(sub ref) - Iterates over an array, executing the subroutine for each element in the array. If you wish to modify or otherwise act directly on the contents of the array, use $_ within your sub reference.
e.g. To increment all elements in the array by one...
$sao->foreach(sub{ ++$_ });
get - Alias for the indices() method.
index(val) - Returns the index of the first element of the array object that contains val. Returns undef if no value is found.
Note that there is no dereferencing here so if youre looking for an item nested within a ref, use the flatten method first.
indices(val1,?val2?, ?val...?) - Returns an array consisting of the elements at the specified indices or undef if the element is out of range.
A range may also be used. It must be a quoted string in 0..3 format.
join(?char?) - Joins the individual elements of the list into a single string with the elements separated by the value of char. Useful in conjunction with the print() method. If no character is specified, then char defaults to a comma.
e.g. $sao->join(-)->print;
last() - Returns the last element of the array (or undef).
length() - Returns the number of elements within the array.
max() - Returns the maximum value of an array. No effort is made to check for non-numeric data.
pack(template) - Packs the contents of the array into a string (in scalar context) or a single array element (in object or void context).
pop() - Removes the last element from the array. Returns the popped element.
print(?1?) - Prints the contents of the array. If a 1 is provided as an argument, the output will automatically be terminated with a newline.
This also doubles as a contents method, if you just want to make a copy of the array, e.g. my @copy = $sao->print;
Can be called in void or list context, e.g.
$sao->print(); # or... print "Contents of array are: ", $sao->print();
push(list) - Adds list to the end of the array, where list is either a scalar value or a list. Returns an array or array reference in list or scalar context, respectively. Note that it does not return the length in scalar context. Use the length method for that.
reverse() - Reverses the order of the contents of the array.
rindex(val) - Similar to the index() method, except that it returns the index of the last val found within the array.
set(index,value) - Sets the element at index to value, replacing whatever may have already been there.
shift() - Shifts the first element of the array and returns the shifted element.
sort(?coderef?) - Sorts the contents of the array in alphabetical order, or in the order specified by the optional coderef. Use your standard $a and $b variables within your calling program, e.g:
my $sao = Set::Array->new( { name => Berger, salary => 20000 }, { name => Berger, salary => 15000 }, { name => Vera, salary => 25000 }, );
my $subref = sub{ $b->{name} cmp $a->{name} || $b->{salary} $a->{salary} };
$sao14->sort($subref)->flatten->join->print(1);
splice(?offset?,?length?,?list?) - Splice the array starting at position offset up to length elements, and replace them with list. If no list is provided, all elements are deleted. If length is omitted, everything from offset onward is removed.
Returns an array or array ref in list or scalar context, respectively. This method always modifies the object, regardless of context. If your goal was to grab a range of values without modifying the object, use the indices method instead.
unique() - Removes/returns non-unique elements from the list.
unshift(list) - Prepends a scalar or list to array. Note that this method returns an array or array reference in list or scalar context, respectively. It does not return the length of the array in scalar context. Use the length method for that.
ODDBALL METHODS
as_hash() - Returns a hash based on the current array, with each even numbered element (including 0) serving as the key, and each odd element serving as the value. This can be switched by using the key_order option and setting it to odd, in which case the even values serve as the values, and the odd elements serve as the keys. The default is even.
Of course, if you dont care about insertion order, you could just as well do something like, $sao-reverse->as_hash;>
Carp::croaks if the array contains an odd number of elements. This method does not actually modify the object itself in any way. It just returns a plain hash in list context or a hash reference in scalar context. The reference is not blessed, therefore if this method is called as part of a chain, it must be the last method called.
impose(?append/prepend?,string) - Appends or prepends the specified string to each element in the array. Specify the method by using either the keyword append or prepend. The default is append.
randomize() - Randomizes the order of the elements within the array.
rotate(direction) - Moves the last item of the list to the front and shifts all other elements one to the right, or vice-versa, depending on what you pass as the direction - ftol (first to last) or ltof (last to first). The default is ltof.
e.g. my $sao = Set::Array->new(1,2,3);
$sao->rotate(); # order is now 3,1,2
$sao->rotate(ftol); # order is back to 1,2,3
Download (0.023MB)
Added: 2007-07-23 License: Perl Artistic License Price:
823 downloads
RIR to DNS converter 0.1
RIR to DNS converter is a tool to convert Regional Internet Registry data to a DNS country lookup zone. more>>
RIR to DNS converter is a tool to convert Regional Internet Registry data to a DNS country lookup zone. You can use it to build your own DNS zone for looking up country codes from IP addresses.
It uses data directly from RIPE, ARIN, APNIC, LACNIC, and AFRINIC. The data can be updated on a schedule of your choosing.
The input data comes from:
ftp://ftp.afrinic.net/pub/stats/afrinic/delegated-afrinic-latest
ftp://ftp.apnic.net/pub/stats/apnic/delegated-apnic-latest
ftp://ftp.arin.net/pub/stats/arin/delegated-arin-latest
ftp://ftp.ripe.net/pub/stats/ripencc/delegated-ripencc-latest
ftp://ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-latest
The input data format is described in:
http://www.apnic.net/db/rir-stats-format.html
The output is a BIND 9 zone file that can be used to look up country codes
in a similar fashion to in-addr.arpa. For example, to find out what country
203.30.47.58 is:
host 58.47.30.203.rir.example.com
58.47.30.203.rir.example.com has address 127.0.65.86
where 65 and 85 are ASCII for A and U, which means 203.30.47.58 is
in Australia (AU).
HOW TO USE IT
Just feed it the above delegated- -latest files into stdin and it will
spit out the zone file to stdout. The zone file will only have the IP addresses,
so you could $INCLUDE it into a zone file that contains NS records, SOA, $ORIGIN,
etc.
WHY USE IT
You dont need the resolution of MaxMinds GeoIP database, but you do want
something that is free and you want it kept up to date on a schedule that
you decide.
You could use this to block or tag email based on countries, block or redirect
visitors to your website based on end-user country, and so on. Be very
careful about blocking mail this way, though, as you may block legitimate
email. Instead of blocking outright, use it in a SpamAssassin rule to add
something to the spam level, based on where the email comes from.
HOW IT WORKS
The RIR files contain ranges of IP addresses, and indicate what CC each range is allocated to. At the simplest level, rir2dns just sorts the ranges then iterates
through the IPs in each range and generates a reverse-dns-style A record that
represents the country code.
HOW IT WORKS - IN DETAIL
Rather than iterate through each IP address, the program tries to skip through
entire classes at a time (256 IPs, 65536 IPs, etc). Rather than iterate
through each IP, the loop iterates through classes or IP ranges (whichever are
smaller at the loop control), using control-breaks to accummulate neighbouring
ranges where possible so that entire classes that are in the same country dont
generate huge numbers of records.
Firstly, IPs are considered to be 4-digit numbers, but in base-256. In other
words, each octet is dealt with as if it were a single base-256 digit. This
turns out to be convenient because optimisations of large chunks of IP space can be done by looking for places where least-significant base-256 digits are zero.
Next, IP ranges are broken down into the following sub-ranges:
Optional individual IP addresses (ie: 4 octets)
Optional A-class ranges (ie: 3 octets)
Optional B-class ranges (ie: 2 octets)
Optional C-class ranges (ie: 1 octet)
Optional B-class ranges (ie: 2 octets)
Optional A-class ranges (ie: 3 octets)
Optional individual IP addresses (ie: 4 octets)
Considering that there is a pattern here, Im sure theres an elegant way to
handle breaking this down into two loops (one reducing the octets and one
increasing the octets), but I cant be bothered, so Ill break it down into
seven loops. Kind of hard-coded, but at least its simple.
For ease of processing, the IP addresses are actually converted to 32-bit numbers, then back again. This simplifies mathematics and looping through ranges.
Thats pretty much it, really...
Note that currently there are about 80,000 RIR records between all five
registries. This takes about 35 seconds on a 2.4GHz P4 to process, and
generates a 26MB file with around 3/4 million lines (RRs). This causes BIND
to use about 100MB or so of memory, and on a slow machine will probably cause it to take too long to reply, while it searches the zone. That size zone can
take a minute or two to load, which is quite a while.
Basic algorithm:
Read & process RIR data:
Read RIR ranges
Sort RIR ranges by start IP address
Glue together contiguous ranges of the same country
For each range
Generate the IPs at the start of the range
Generate the A-classes at the start of the range
Generate the B-classes at the start of the range
Generate the C-classes in the middle of the range
Generate the B-classes at the end of the range
Generate the A-classes at the end of the range
Generate the IPs at the end of the range
<<lessIt uses data directly from RIPE, ARIN, APNIC, LACNIC, and AFRINIC. The data can be updated on a schedule of your choosing.
The input data comes from:
ftp://ftp.afrinic.net/pub/stats/afrinic/delegated-afrinic-latest
ftp://ftp.apnic.net/pub/stats/apnic/delegated-apnic-latest
ftp://ftp.arin.net/pub/stats/arin/delegated-arin-latest
ftp://ftp.ripe.net/pub/stats/ripencc/delegated-ripencc-latest
ftp://ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-latest
The input data format is described in:
http://www.apnic.net/db/rir-stats-format.html
The output is a BIND 9 zone file that can be used to look up country codes
in a similar fashion to in-addr.arpa. For example, to find out what country
203.30.47.58 is:
host 58.47.30.203.rir.example.com
58.47.30.203.rir.example.com has address 127.0.65.86
where 65 and 85 are ASCII for A and U, which means 203.30.47.58 is
in Australia (AU).
HOW TO USE IT
Just feed it the above delegated- -latest files into stdin and it will
spit out the zone file to stdout. The zone file will only have the IP addresses,
so you could $INCLUDE it into a zone file that contains NS records, SOA, $ORIGIN,
etc.
WHY USE IT
You dont need the resolution of MaxMinds GeoIP database, but you do want
something that is free and you want it kept up to date on a schedule that
you decide.
You could use this to block or tag email based on countries, block or redirect
visitors to your website based on end-user country, and so on. Be very
careful about blocking mail this way, though, as you may block legitimate
email. Instead of blocking outright, use it in a SpamAssassin rule to add
something to the spam level, based on where the email comes from.
HOW IT WORKS
The RIR files contain ranges of IP addresses, and indicate what CC each range is allocated to. At the simplest level, rir2dns just sorts the ranges then iterates
through the IPs in each range and generates a reverse-dns-style A record that
represents the country code.
HOW IT WORKS - IN DETAIL
Rather than iterate through each IP address, the program tries to skip through
entire classes at a time (256 IPs, 65536 IPs, etc). Rather than iterate
through each IP, the loop iterates through classes or IP ranges (whichever are
smaller at the loop control), using control-breaks to accummulate neighbouring
ranges where possible so that entire classes that are in the same country dont
generate huge numbers of records.
Firstly, IPs are considered to be 4-digit numbers, but in base-256. In other
words, each octet is dealt with as if it were a single base-256 digit. This
turns out to be convenient because optimisations of large chunks of IP space can be done by looking for places where least-significant base-256 digits are zero.
Next, IP ranges are broken down into the following sub-ranges:
Optional individual IP addresses (ie: 4 octets)
Optional A-class ranges (ie: 3 octets)
Optional B-class ranges (ie: 2 octets)
Optional C-class ranges (ie: 1 octet)
Optional B-class ranges (ie: 2 octets)
Optional A-class ranges (ie: 3 octets)
Optional individual IP addresses (ie: 4 octets)
Considering that there is a pattern here, Im sure theres an elegant way to
handle breaking this down into two loops (one reducing the octets and one
increasing the octets), but I cant be bothered, so Ill break it down into
seven loops. Kind of hard-coded, but at least its simple.
For ease of processing, the IP addresses are actually converted to 32-bit numbers, then back again. This simplifies mathematics and looping through ranges.
Thats pretty much it, really...
Note that currently there are about 80,000 RIR records between all five
registries. This takes about 35 seconds on a 2.4GHz P4 to process, and
generates a 26MB file with around 3/4 million lines (RRs). This causes BIND
to use about 100MB or so of memory, and on a slow machine will probably cause it to take too long to reply, while it searches the zone. That size zone can
take a minute or two to load, which is quite a while.
Basic algorithm:
Read & process RIR data:
Read RIR ranges
Sort RIR ranges by start IP address
Glue together contiguous ranges of the same country
For each range
Generate the IPs at the start of the range
Generate the A-classes at the start of the range
Generate the B-classes at the start of the range
Generate the C-classes in the middle of the range
Generate the B-classes at the end of the range
Generate the A-classes at the end of the range
Generate the IPs at the end of the range
Download (0.60MB)
Added: 2007-04-27 License: GPL (GNU General Public License) Price:
913 downloads
Algorithm::CurveFit 1.03
Algorithm::CurveFit - Nonlinear Least Squares Fitting. more>>
Algorithm::CurveFit - Nonlinear Least Squares Fitting.
SYNOPSIS
use Algorithm::CurveFit;
# Known form of the formula
my $formula = c + a * x^2;
my $variable = x;
my @xdata = read_file(xdata); # The data corresponsing to $variable
my @ydata = read_file(ydata); # The data on the other axis
my @parameters = (
# Name Guess Accuracy
[a, 0.9, 0.00001], # If an iteration introduces smaller
[c, 20, 0.00005], # changes that the accuracy, end.
);
my $max_iter = 100; # maximum iterations
my $square_residual = Algorithm::CurveFit->curve_fit(
formula => $formula, # may be a Math::Symbolic tree instead
params => @parameters,
variable => $variable,
xdata => @xdata,
ydata => @ydata,
maximum_iterations => $max_iter,
);
use Data::Dumper;
print Dumper @parameters;
# Prints
# $VAR1 = [
# [
# a,
# 0.201366784209602,
# 1e-05
# ],
# [
# c,
# 1.94690440147554,
# 5e-05
# ]
# ];
#
# Real values of the parameters (as demonstrated by noisy input data):
# a = 0.2
# c = 2
Algorithm::CurveFit implements a nonlinear least squares curve fitting algorithm. That means, it fits a curve of known form (sine-like, exponential, polynomial of degree n, etc.) to a given set of data points.
For details about the algorithm and its capabilities and flaws, youre encouraged to read the MathWorld page referenced below. Note, however, that it is an iterative algorithm that improves the fit with each iteration until it converges. The following rule of thumb usually holds true:
A good guess improves the probability of convergence and the quality of the fit.
Increasing the number of free parameters decreases the quality and convergence speed.
Make sure that there are no correlated parameters such as in a + b * e^(c+x). (The example can be rewritten as a + b * e^c * e^x in which c and b are basically equivalent parameters.
The curve fitting algorithm is accessed via the curve_fit subroutine. It requires the following parameters as key => value pairs:
formula
The formula should be a string that can be parsed by Math::Symbolic. Alternatively, it can be an existing Math::Symbolic tree. Please refer to the documentation of that module for the syntax.
Evaluation of the formula for a specific value of the variable (X-Data) and the parameters (see below) should yield the associated Y-Data value in case of perfect fit.
variable
The variable is the variable in the formula that will be replaced with the X-Data points for evaluation. If omitted in the call to curve_fit, the name x is default. (Hence xdata.)
params
The parameters are the symbols in the formula whose value is varied by the algorithm to find the best fit of the curve to the data. There may be one or more parameters, but please keep in mind that the number of parameters not only increases processing time, but also decreases the quality of the fit.
The value of this options should be an anonymous array. This array should hold one anonymous array for each parameter. That array should hold (in order) a parameter name, an initial guess, and optionally an accuracy measure.
Example:
$params = [
[parameter1, 5, 0.00001],
[parameter2, 12, 0.0001 ],
...
];
Then later:
curve_fit(
...
params => $params,
...
);
The accuracy measure means that if the change of parameters from one iteration to the next is below each accuracy measure for each parameter, convergence is assumed and the algorithm stops iterating.
In order to prevent looping forever, you are strongly encouraged to make use of the accuracy measure (see also: maximum_iterations).
The final set of parameters is not returned from the subroutine but the parameters are modified in-place. That means the original data structure will hold the best estimate of the parameters.
xdata
This should be an array reference to an array holding the data for the variable of the function. (Which defaults to x.)
ydata
This should be an array reference to an array holding the function values corresponding to the x-values in xdata.
maximum_iterations
Optional parameter to make the process stop after a given number of iterations. Using the accuracy measure and this option together is encouraged to prevent the algorithm from going into an endless loop in some cases.
The subroutine returns the sum of square residuals after the final iteration as a measure for the quality of the fit.
<<lessSYNOPSIS
use Algorithm::CurveFit;
# Known form of the formula
my $formula = c + a * x^2;
my $variable = x;
my @xdata = read_file(xdata); # The data corresponsing to $variable
my @ydata = read_file(ydata); # The data on the other axis
my @parameters = (
# Name Guess Accuracy
[a, 0.9, 0.00001], # If an iteration introduces smaller
[c, 20, 0.00005], # changes that the accuracy, end.
);
my $max_iter = 100; # maximum iterations
my $square_residual = Algorithm::CurveFit->curve_fit(
formula => $formula, # may be a Math::Symbolic tree instead
params => @parameters,
variable => $variable,
xdata => @xdata,
ydata => @ydata,
maximum_iterations => $max_iter,
);
use Data::Dumper;
print Dumper @parameters;
# Prints
# $VAR1 = [
# [
# a,
# 0.201366784209602,
# 1e-05
# ],
# [
# c,
# 1.94690440147554,
# 5e-05
# ]
# ];
#
# Real values of the parameters (as demonstrated by noisy input data):
# a = 0.2
# c = 2
Algorithm::CurveFit implements a nonlinear least squares curve fitting algorithm. That means, it fits a curve of known form (sine-like, exponential, polynomial of degree n, etc.) to a given set of data points.
For details about the algorithm and its capabilities and flaws, youre encouraged to read the MathWorld page referenced below. Note, however, that it is an iterative algorithm that improves the fit with each iteration until it converges. The following rule of thumb usually holds true:
A good guess improves the probability of convergence and the quality of the fit.
Increasing the number of free parameters decreases the quality and convergence speed.
Make sure that there are no correlated parameters such as in a + b * e^(c+x). (The example can be rewritten as a + b * e^c * e^x in which c and b are basically equivalent parameters.
The curve fitting algorithm is accessed via the curve_fit subroutine. It requires the following parameters as key => value pairs:
formula
The formula should be a string that can be parsed by Math::Symbolic. Alternatively, it can be an existing Math::Symbolic tree. Please refer to the documentation of that module for the syntax.
Evaluation of the formula for a specific value of the variable (X-Data) and the parameters (see below) should yield the associated Y-Data value in case of perfect fit.
variable
The variable is the variable in the formula that will be replaced with the X-Data points for evaluation. If omitted in the call to curve_fit, the name x is default. (Hence xdata.)
params
The parameters are the symbols in the formula whose value is varied by the algorithm to find the best fit of the curve to the data. There may be one or more parameters, but please keep in mind that the number of parameters not only increases processing time, but also decreases the quality of the fit.
The value of this options should be an anonymous array. This array should hold one anonymous array for each parameter. That array should hold (in order) a parameter name, an initial guess, and optionally an accuracy measure.
Example:
$params = [
[parameter1, 5, 0.00001],
[parameter2, 12, 0.0001 ],
...
];
Then later:
curve_fit(
...
params => $params,
...
);
The accuracy measure means that if the change of parameters from one iteration to the next is below each accuracy measure for each parameter, convergence is assumed and the algorithm stops iterating.
In order to prevent looping forever, you are strongly encouraged to make use of the accuracy measure (see also: maximum_iterations).
The final set of parameters is not returned from the subroutine but the parameters are modified in-place. That means the original data structure will hold the best estimate of the parameters.
xdata
This should be an array reference to an array holding the data for the variable of the function. (Which defaults to x.)
ydata
This should be an array reference to an array holding the function values corresponding to the x-values in xdata.
maximum_iterations
Optional parameter to make the process stop after a given number of iterations. Using the accuracy measure and this option together is encouraged to prevent the algorithm from going into an endless loop in some cases.
The subroutine returns the sum of square residuals after the final iteration as a measure for the quality of the fit.
Download (0.011MB)
Added: 2007-05-16 License: Perl Artistic License Price:
893 downloads
IFSgr 1.1
IFSgr is a command line two-dimensional linear IFS (Iterated Function System) grayscale renderer. more>>
IFSgr is a command line two-dimensional linear IFS (Iterated Function System) grayscale renderer.
IFSgr uses Fractints IFS file format, and features automatic fractal scaling and gray level adjustment and consistent image look independent of size or the numbers of iterations.
It can also convert Fractint files to Gimp IFS Compose files and back.
Main features:
- Reads and writes Fractint 2D IFS files, allowing to select particular fractals from them with easy :: notation.
- Reads FDESIGN TRN files.
- Reads and writes Gimp IFS Compose (IFSC) files.
- Renders high-quality grayscale images (see the IFS gallery), automatically scaling the fractals to fit to the canvas and adjusting gray levels.
- Writes Portable GrayMap images with bit depth 8 or 16, or raw pixel hit counts in pseudo-PGM format (like PGM but with 32bit depth).
- Can rotate, skew, asymmetricaly scale or flip the fractal before rendering or exporting to another format
- Allows selection of speed/quality trade-off and gamma (darkness) modification.
- Keeps consistent image impression the same when changing size or the number of iterations (quality).
- Can estimate box-counting dimension of the fractals.
- Its functionality is available as a library, libifsgr.
Enhancements:
- The code should be 64-bit clean now.
<<lessIFSgr uses Fractints IFS file format, and features automatic fractal scaling and gray level adjustment and consistent image look independent of size or the numbers of iterations.
It can also convert Fractint files to Gimp IFS Compose files and back.
Main features:
- Reads and writes Fractint 2D IFS files, allowing to select particular fractals from them with easy :: notation.
- Reads FDESIGN TRN files.
- Reads and writes Gimp IFS Compose (IFSC) files.
- Renders high-quality grayscale images (see the IFS gallery), automatically scaling the fractals to fit to the canvas and adjusting gray levels.
- Writes Portable GrayMap images with bit depth 8 or 16, or raw pixel hit counts in pseudo-PGM format (like PGM but with 32bit depth).
- Can rotate, skew, asymmetricaly scale or flip the fractal before rendering or exporting to another format
- Allows selection of speed/quality trade-off and gamma (darkness) modification.
- Keeps consistent image impression the same when changing size or the number of iterations (quality).
- Can estimate box-counting dimension of the fractals.
- Its functionality is available as a library, libifsgr.
Enhancements:
- The code should be 64-bit clean now.
Download (0.081MB)
Added: 2006-03-14 License: GPL (GNU General Public License) Price:
1321 downloads
Secleted [ 0 ] software to compare
Copyright Notice:
Software piracy is theft, Using crack, password, serial numbers, registration codes, key generators is illegal and prevent future software development. The above iterated search only lists software in full, demo and trial versions for free download. Download links are directly from our mirror sites or publisher sites, torrent files or links from rapidshare.com, yousendit.com or megaupload.com are not allowed