List-Comprehensions

 view release on metacpan or  search on metacpan

lib/List/Comprehensions.pm  view on Meta::CPAN

package List::Comprehensions;
use warnings;
use Carp;

# for comp2
use Alias qw(attr);
use Array::RefElem qw(av_push);
use PadWalker qw(peek_my);

require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(comp1 comp2 P PF);

$VERSION = 0.13;

=head1 NAME

List::Comprehensions - allows for list comprehensions in Perl.

=head1 SYNOPSIS

    use List::Comprehensions;
    use warnings;
    
    my @res = ();

    @res = comp1 { [ @_ ] } [0..4], [0..4], [0..4];

    no warnings 'once';
    @res = comp2 { [$i, $j, $k] }
        i => [0..4],
        j => [0..4],
        k => [0..4];

    # if strict 'vars' is on, use lexicals. eg:
    use strict 'vars';
    
    my ($i, $j, $k);
    @res = comp2 { [$i, $j, $k] }
        i => [0..4],
        j => [0..4],
        k => [0..4];
    
    # each being less efficient but equivelant to

    @res = ();
    for $i ( 0..4 ) {
        for $j ( 0..4 ) {
            for $k ( 0..4 ) {
                push @res, [$i, $j, $k];
            }
        }
    }

=head1 FUNCTIONS

=over 4

=cut

sub min_length_of {
	my $min = scalar( @{$_[0]} );

	my ($i, $len);
	for $i ( 1..$#_ ) {
		$len = scalar( @{$_[$i]} );
		$min = $len if $len < $min;
	}



( run in 0.989 second using v1.01-cache-2.11-cpan-e1769b4cff6 )