MLUG: Re: [MLUG] Need Program, Mind Not Working
Re: [MLUG] Need Program, Mind Not Working
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

On Thu, 6 Dec 2001, Stephen Montgomery-Smith wrote:

> Wrong again:
>
> #!/usr/bin/perl -w
> open F,"find -d . |";
> while (<F>) {
>   chomp;
>   if (/(.*)\/(.+)/) {

It's a matter of taste, but when you're trying to match directory
paths, it's sometimes nice to use the match operator by name and
use balanced delimiters:

    if (m{(.*)/(.+)})

Or if you're really anal retentive,

    if (m{
           (.*) # directory name?
              / # path separator
           (.+) # file name
         }x)    # x gives you comments and special white space treatment

>     $dir=$1;
>     $file=lc($2);
>     $file=~s/\ /\_/g;
>     $dir=~s/\ /\\\ /g;
>     s/\ /\\\ /g;

Similarly:

      $file =~ s{\ }{\_}g;
      $dir  =~ s{\ }{\\\ }g;
               s{\ }{\\\ }g;  # match against $_

Not that shell protection is every pretty, mind you...

jking






>     system "mv $_  $dir/$file\n";
>   }
> }
>
>
>

--
To unsubscribe, go to http://mlug.missouri.edu/members/edit.php

Archives are available at http://mlug.missouri.edu/list-archives/