Algorithm-Loops

 view release on metacpan or  search on metacpan

ex/MatrixMult.plx  view on Meta::CPAN

                if  $fmt =~ /\./;
        }
        return $str;
    }

}


sub Main {
    if(  ! @_  ) {
        open STDIN, "<&DATA"
            or  die "Can't dup DATA to STDIN: $!\n";
    }
    my( @lines, $mat, $x, $p );
    do {
        $_= <>;
        $_= ''   if  ! defined $_  ||  $_ eq /^__END__\b/;
        if(  ! /\d/  ) {   # Numberless line between matrices:
            if(  $mat  &&  ! /^And\s*$/  ) {
                if(  ! $x  &&  $p  ) {
                    print "And\n";
                }

ex/NaturalSort.plx  view on Meta::CPAN

# (represented by a sequence of 9 or fewer consecutive digits) anywhere
# in the strings are sorted in numeric order relative to each other.

# The first version doesn't correctly sort integers with leading zeros.

# Both versions output extra digits if
# given a sequence of 10 or more digits.

use Algorithm::Loops qw( Filter );

@ARGV= split ' ', <DATA>
    if  ! @ARGV;

print join " ", Filter {
    s/\d(\d+)/$1/g
} sort
&Filter( sub {
    s/(\d+)/length($1).$1/ge
}, @ARGV );

print join " ", Filter {

t/assert.t  view on Meta::CPAN

);

ok(1); #1# Loaded module

my $croak= eval { require Carp; defined &Carp::croak }
    ?  0  :  "Carp::croak() not found";
print "# $@"   if  $@;
my $check;
my $lineNum;
sub SetLineNum { $lineNum= 1+(caller(0))[2]; }
while(  <DATA>  ) {
    $lineNum++;
    chomp;
    if(  m#^[/0]#  ) {
        $check= $_;
        next;
    }
    next   if  m/^#/;
    if(  s#^:##  ) {
        eval "\n#line $lineNum $0\n$_\n; 1"
          or  die $@;

t/assert.t  view on Meta::CPAN

    }
    ok( $@, "/^$sub:/", "name: $_" )   if  $sub;
    ok( $@, $check, "mesg: $_" )   if  $check;
    skip( $croak, $@, "/ at ".quotemeta(__FILE__)." line /", "line: $_" )
        if  '' ne $croak;
}
exit( 0 );

# This code fixes up test numbers below:
{
    seek( DATA, 0, 0 );
    while(  <DATA>  ) {
        print;
        last   if  /^\s*__END__/;
    }
    my $croak= 1;
    my $check= 0;
    my $n= 2;
    while(  <DATA>  ) {
        if(  m#^[/0]#  ) {
            chomp( $check= $_ );
        } elsif(  /^:/  ) {
            $croak= 0   if  /croak/;
        } elsif(  /^#/  ) {
            ;
        } else {
            if(  ! s/\s*#.*//s  ) {
                chomp;
            }



( run in 0.807 second using v1.01-cache-2.11-cpan-140bd7fdf52 )