Moving files

Bob Bell bobbell at zk3.dec.com
Mon Jan 6 12:05:50 EST 2003


On Mon, Jan 06, 2003 at 11:55:28AM -0500, Erik Price <eprice at ptc.com> wrote:
> Michael O'Donnell wrote:
> >>      perl -e 'opendir DIR,".";@f = grep { ! /^\./ && -f $_ } 
> >>      readdir(DIR);\
> >>        map {($n = $_)=~ s/\s+/_/g; rename ($_, $n) } @f;'
> >
> <code>map {($n = $_)=~ s/\s+/_/g; rename ($_, $n) }</code>
> assign "the default item [passed from the previous grep function]" to 
> the variable "n" and then substitute all whitespace in that item for an 
> underscore, then rename the default item to the string contained in "n", 
> but do this for each item in the "f" array.

    One nit: the $_ in the anonymous block passed to map does not come
from grep.  Rather, it is a reference to each item (in turn) in the
provided list (here, @f).

    [ FWIW, I'm surprised Paul bothered to use @f, instead of just
applying map to the results of grep directly ]

    Also: rather than "substitute all whitespace in that item for an
underscore", it is more accurate to say "substitute each occurance of
a sequence of whitespace characters in that item with a underscore",
though I believe that's what you meant.

-- 
Bob Bell <bobbell at zk3.dec.com>
-------------------------------------------------------------------------
 "MSN [the Microsoft Network] has a guy whose full time job is
  walking around rebooting NT Servers as they crash."
   -- Alex St. John, former Microsoft employee



More information about the gnhlug-discuss mailing list