Slash Boxes
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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Looks Nice (Score:3, Insightful)

    by Ovid (2709) on 2003.12.17 12:46 (#26640) Homepage Journal

    Hmm ... seems like an awful lot of duplicated code for checking the file status. Five subs are identical, so I deleted them.

    package File::Finder::Steps;

    use constant OFFSET => qr/^(\+|-|)(.*)/;

    my %status = (
        links => '(stat(_))[3]',
        inum  => '(stat(_))[1]',
        atime => 'int(-A _)',
        mtime => 'int(-M _)',
        ctime => 'int(-C _)',

    while (my ($sub,$op) = each %status) {
        eval <<"    END_SUB";
        sub $sub {
            my \$self = shift;
            my (\$prefix, \$n) = shift =~ OFFSET;

            return sub {
              _n(\$prefix, \$n, $op);

    Passes quite nicely, though not every would care for that :)

    • Heh. Earlier today, I read Schwern's paper on accessors and closures []. Is it me, or is there more than some similarity in the problem statement?

      # And then eval() a new subroutine for each of them.
      foreach my $accessor (@Accessors) {
          eval qq{
              sub $accessor {
                  my(\$self) = shift;
                  if( \@_ ) {
                      my \$data = shift;

      • Yeah, this is a technique I use a lot, though really I should have done this:

        my %status = (
          links => sub { (stat(_))[3] },
          inum  => sub { (stat(_))[1] },
          atime => sub { int(-A _) },
          mtime => sub { int(-M _) },
          ctime => sub { int(-C _) },

        while (my ($function,$op) = each %status) {
          no strict 'refs';
          *$function = sub {
            my $self = shift;
            my ($prefix, $n) = shift =~ OFFSET;

            return sub {

  • Pick up the docs at For some reason, typing File::Finder in the search box doesn't pull it up at all.
    It does now. Remember, PAUSE, the CPAN, and are only loosely coupled, and it takes time for changes to filter through from one to t'other.