in reply to Sorting names using Regular Expressions and placing them in different Files.

It sounds to me like you don't want files "BSC", "SBSCSubsystem", and "MCBTSSubsystem", but rather directories, and to have the 20041202 files prefixed with those moved into the directories? If so, try doing one category at a time:
for my $category ("BSC", "SBSCSubsystem", "MCBTSSubsystem") { }
Inside the loop you'll need to:
  1. create the directory if it doesn't exist, like:
    use Errno "EEXIST"; if (! mkdir("foo") && $! != EEXIST) { die "unable to create directory +foo: $!" }
  2. find any matching files and put them in @files. I wouldn't use a regular expression; I'd just use glob.
  3. move @files into your directory. No File I/O required, rename($file, "dirname/$file") should work to move $file from the current directory into directory dirname.

Update: added use Errno

Replies are listed 'Best First'.
Re^2:Sorting names using Regular Expressions and placing them in different Files.
by santhi (Monk) on Dec 29, 2006 at 04:58 UTC
    I think you need to move the files that start with BSC, SBSCSubsytem and MCBTSSubSystem into separate directories.

    1. Create the separate directories for BSD, SBSCSubsystem and MCBTSSubsytem under the directory you want to search or at nay other path
    chdir("test") ## For eg:test can be directory where the files exist. unless (-d "BSD"){ mkdir("BSD") or warn ("unable to create directory BSD"); } unless (-d "SBSCSubsystem"){ mkdir("SBSCSubsystem") or warn ("unable to create directory SBSCSu +bsystem"); } unless (-d "MCBTSSubsytem"){ mkdir("MCBTSSubsytem") or warn ("unable to create directory MCBTSS +ubsytem"); }
    Get the lsit of files that matches the BSD, MCBTSSubsytem etc into separate arrays.
    opendir(DIR, "test") @files_BSD = grep(/^BSD-\d{14}/, readdir(DIR)); @files_SBSC = grep(/^SBSCSubsystem-\d{14}/, readdir(DIR)); @files_MCBTS = grep(/^MCBTSSubsytem-\d{14}/, readdir(DIR));
    Then move the files into respective directories.
    foreach (@files_BSD){ rename($_, "BSD/$_" ); } foreach (@files_SBSC){ rename($_, "SBSCSubsystem/$_"); } foreach (@files_MCBTS){ rename($_, "MCBTSSubsytem/$_"); }
    A reply falls below the community's threshold of quality. You may see it by logging in.