NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
There's no fold in List::Util or List::MoreUtils (Score:1)
Anyway, here's a fold-using implementation:
use strict;
sub fold {
my $accum = shift;
my $code = shift;
return $accum unless @_;
return fold( $code->( $accum, shift ), $code, @_ );
}
my @files = qw(
00000.diff
00001.diff
00002.diff
00003.copy
00004.diff
00005.diff
00006.copy
00007.diff
00008.diff
);
use Data::Dumper;
sub foldee {
my ( $accum, $item ) = @_;
return [$item, []] if ( $item =~
return $accum unless defined $accum->[ 0 ];
return [ $accum->[ 0 ], [@{$accum->[1]}, $item]];
}
print Dumper(fold( [undef, []], \&foldee, @files));
Reply to This