I'm new to CPAN (as an developer) and I have a module that I would like to upload to CPAN.
I was hoping to get some feedback on an appropriate Namespace. It provides two @array processing functions. I was thinking it might have a place in the List:: namespace but it doesn't actually work on lists but arrays or references to them. Any suggestions are welcome. Thanks, -Lee #### MODULE INFO #################### findone usage: findone { coderef }, @array , OPTIONAL start_index OPTIONAL end_index findfirst usage: findfirst { coderef }, @array , OPTIONAL start_index OPTIONAL end_index This is a basically a lazy grep. Will return the first element found. On subsequent calls it will return subsequent elements. undef if none are left. If called in a list context, it will return ($match,$index); If called in a scalar context, just returns $match. # contrived examples. while (my ($sku,$index) = findone { $_->{'price'} > 100 && $_->{'desc'} =~/^tv\b/ } @products ) { # When called with a while/for/foreach it will keep track internally of the last match. print "Found a $sku at $index that matches criteria."; } my @tokens = qw(some words here); while (my $token = <>){ chomp($token); die "$token not in list!" unless findone { $_ eq @tokens }; # Won't keep track because it's not what we want. } Internally it uses Filter::Simple to change any calls to findone with a call to findfirst unless the current line contains a do, for or foreach statement. This avoids the following gotcha. my @tokens = (tokens here); while ($line =<>){ chomp($line); die "$line is not a valid token" unless findone { m/^$line/ } @tokens; } Because it keeps track of where and what it's called with, it will never match past the first match which means it will fail on the second block. (Unless there are multiple matches in @tokens. Then it will fail on the Matches+1 iteration.) findfirst doesn't store any info about previous calls so it avoids the problem.