After declaring I was taking a programming hiatus only a few days ago, I have written two pieces of code I am fairly proud of. The first was an efficient way to process every line in 1 file against every line in another file without slurping the files into memory.
The second was an iterator for x size subsets of y
#!/usr/bin/perl use strict; use warnings;
my $iter = combo( 3 , 1.. 5 ); while ( my @combo = $iter->() ) { print "@combo\n"; }
sub combo { my $by = shift; return sub { () } if ! $by || $by =~/\D/ || @_ < $by; my @list = @_;
my @position = (0.. $by - 2, $by - 2); my @stop = @list - $by.. $#list; my $end_pos = $#position; my $done = undef;
Fascination With Iterators 0 Comments More | Login | Reply /