Things I Frequently Forget (TIFF)

Perl

Seeking files

This is one of the most useful 'one-liners' I use in Perl scripts. Given an expression and a reference to an array it eats its way through the array searching for the first occurence of the expression. On completion, the 'eaten' array is returned and the The $array reference contains what is left of the array (if anything) including the entry that matches $expr.

sub Seek {
    my ($expr,$array) = @_;
    push(@ret,shift(@{$array})) while (@$array && $array->[0] !~ m/$expr/);
    return @ret;
}