in reply to Can you teach a new dog an old trick?

The only change I would make is to add this line:

die "file already exists\n" if -e "tmp"

at the top, just to avoid clobbering any existing tmp files or directories or whatever.

Replies are listed 'Best First'.
Re: Can you teach a new dog an old trick?
by mandog (Curate) on Jul 30, 2001 at 23:24 UTC
    Could the code to recurse through sub directories, processing all the *.html be added in only a few lines?
      You want to use File::Find to deal with that.

      use strict; use File::Find; find( sub { return unless -f $_ and /\.html?$/; # do your funky thang }, shift || '.' );

      That is, recurse starting from the directory given on the command line, or the current directory if nothing is specified. Then, only for directory entries that are files whose extension is .htm or .html, do whatever makes you happy.

      --
      g r i n d e r
      My dirty code for descending subdirectories used the unix find command to generate a list of files to be acted on. In my case, to chmod files.

      %perl -e '@list = `find . -name "*.htm"`; foreach (@list) {`chmod 644 +$_`}'

        or even:

        find . -name "*.htm" -type file -exec perl -e 's/arse/tits/' {} \;

        just to go even more off topic - your code, although an example, is kind of redunandant; using perl to use find to return a list for perl to use chmod on is unnecessary. all you really need to do is  find . -type file -exec chmod 644 {} \; (but then that's nothing really to do with perl, other than how not to use it. :-)

        Why use perl at all for that? ;)

        Perl's a great language, but no point going hybrid for something like this.

        find . -name \*.htm -exec chmod 644 {} \;

        pstickne
        Use the right tool for the job