Re: help in linux shell script in copying files

From: John W. Krahn (krahnj@acm.org)
Date: 01/29/03


From: "John W. Krahn" <krahnj@acm.org>
Date: Wed, 29 Jan 2003 22:34:41 GMT

Laplace wrote:
>
> if the "first letter is "A" or "a" copy it from \temp\ to \data\A\.... until
> finished A
> if the "first letter is "A" or "a" copy it from \temp\ to \data\A\.... until
> finished A to Z....
>
> algorithm
>
> if the "first letter is "A" or "a" copy it from \temp\ to \data\A\....
>
> if the "first letter is "B" or "b" copy it from \temp\ to \data\B\....
>
> up to Z....
>
> can u show me the script?

#!/usr/bin/perl -w
use strict;
use File::Copy;

my $from = '/temp';
my $to = '/data';

opendir my $dh, $from or die "Cannot open '$from' $!";

while ( defined( my $file = readdir $dh ) ) {
    next unless $file =~ /^([[:alpha:]])/;
    my $first = uc $1;
    mkdir "$to/$first" unless -e "$to/$first";
    copy( "$from/$file", "$to/$first/$file" )
        or warn "Cannot copy $file to $to/$first: $!";
    }

__END__

John

-- 
use Perl;
program
fulfillment


Relevant Pages

  • Re: How to avoid using the slow array subscripting operator?
    ... confuses me is that using the same algorithm, ... So I translated it to perl, ... benchmark or profiling tool to notice the efficiency difference. ... non_cached: 1.18266701698303 sums: 59902 ...
    (perl.beginners)
  • Re: array search speeds?
    ... > impact on the algorithm (Perl programms often use hashes because they ... seem to require more knowledge of C/C++ which I don't have. ...
    (comp.lang.perl.misc)
  • Re: Cumulative/recursive tagged diff/file evolution?
    ... The goal is build of a data set that tags or tokenizes each ... I haven't been able to find any information on doing this in Perl ... not to try to establish an algorithm in the first place. ... Since the referenced article works from the archived change log that ...
    (perl.beginners)
  • Re: Cumulative/recursive tagged diff/file evolution?
    ... Perl, not to try to establish an algorithm in the first place. ... Actually I think "am I recreating the wheel or does this problem have ... a standard solution?" ...
    (perl.beginners)
  • Re: which language should i use?
    ... > It may do some simple hashing and string matching in the first stage. ... > I'm thinking of using perl for this, ... your algorithm, processes it 100 times, and times the ... How fast the production code parses, ...
    (comp.programming)