I see ysth beat me to this one, but here is the code I was working on anyway. It uses the opendir/readdir/loop method:
use strict;
use warnings;
use File::Spec; # for portable filename operations
use File::Path; # to create the new subdirectory
use File::Copy; # to move the edited file
my $currentdir = '.';
my $newdir = File::Spec->catdir( $currentdir, 'newdir' );
# make the new subdirectory
mkpath( $newdir ) or die "error creating $newdir";
# get all filenames in the current directory
opendir( DIR, $currentdir ) or die "couldn't open $currentdir\n";
my @filenames = readdir DIR;
closedir DIR;
# get the program name so it's not moved if $currentdir eq '.'
my ( undef, undef, $progname ) = File::Spec->splitpath( $0 );
foreach my $file (@filenames)
{
# add the full path to the filename
my $pathfile = File::Spec->catfile( $currentdir, $file );
# skip if $file is a directory or this program
if( -d $pathfile or $file eq $progname )
{
next;
}
# process file here
# move file to new subdir
my $newpath = File::Spec->catfile( $newdir, $file );
move( $pathfile, $newpath ) or print "error moving $file";
}
I'm sure more experienced Monks can come up with more elegant solutions, but this works on the tests I performed.
HTH
Update: Fixed code per parv's suggestion.