Re: [ILUG] perl question

From: Justin Mason (jm at domain jmason.org)
Date: Wed 15 Jan 2003 - 12:23:03 GMT


Philip Reynolds said:
> Justin MacCarthy's [macarthy at domain iol.ie] 38 lines of wisdom included:
> > > What is best way to deal with the [files] argument, is there an
> > > easy why to
> > > recurse into the directory and sub directories? Globbing or whatever?
> >
> > Is this decent??? any issues with it ? .....
> Without testing, that could keep running and running and running,
> because you haven't checked if the directory is "." or ".." when you
> run processfile again.

BTW another easier way is to use File::Find, a std part of the perl
distro since perl 5 started. cf. "perldoc File::Find". It's simply
fantastic for this.

    sub processfile {
      my $myfile = shift;
      if (-d $myfile) { # it's a dir, recurse
        use File::Find; File::Find::find (\&wanted, $myfile);
      } else {
        parse_file ($myfile);
      }
    }

    sub wanted {
      return unless (-f $_);
      parse_file ($File::Find::name); # will contain the full path
    }

--j.



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:21:09 GMT