#!/usr/bin/ruby

#
## http://rosettacode.org/wiki/Walk_a_directory/Non-recursively#Sidef
#

func file_match(Block callback, pattern=/\.txt\z/, path=Dir.cwd) {
    path.open(\var dir_h) || return();
    dir_h.entries.each { |entry|
        if (entry.basename ~~ pattern) {
            callback(entry);
        }
    }
}

file_match(
    path: %d'/tmp',
    pattern: /\.p[lm]\z/i,
    callback: { |file|
        say file;
    }
);
