[pm-h] simple perl directory+file task

Russell L. Harris rlharris at oplink.net
Tue Oct 2 18:17:46 PDT 2012


* Lanny Ripple <lanny.ripple at gmail.com> [121002 15:39]:
 
> Building your project in perl will give you a lot of added
> flexibility but just because you have a swiss army chainsaw doesn't
> mean every problem is a... thing you would drive into a piece of
> wood with a chainsaw.  (Doesn't just trip off the tongue does it?)

> Consider
> 
>   $ cat > /tmp/name_me <<'END'
>   #!/bin/bash
>   echo $(basename $1) >> $1
>   END
>   $ chmod 755 /tmp/name_me
>   $ cd datafiles
>   $ find . -type f -print | xargs -n 1 /tmp/name_me

> and your task is also accomplished.  

> Perl can do everything bash and sed can 
...
> but sometimes you don't need perl when simpler tools will do.

Agreed.  My tool of preference is Emacs.

Gratitude and thanks, Lanny.  Your solution saved the day, getting me
past the immediate impasse.  Chainsaw, hand saw, or axe -- in the end,
all that matters is that the tree is felled.  But this was but one of
many trees which I must fell, so other impasses are likely.

I am attempting to resurrect a project which I was forced to set aside
in mid-stream several years ago.  That project necessitates recursion
to perform a series of simple, identical operations on several sets of
data, each of which involves a search-and-replace operation on
literally hundreds of files.

Because of the repetition, my approach back then was to create a set
of Perl scripts; I found it easier to utilize a sequence of about a
dozen simple scripts, rather than try to do everything in one or two
complex scripts.  And the script-writing and processing was going
well, until I was forced to set aside the project.

So, I am reading the latest edition of "Learning Perl" (a few years
ago, I read two of the earlier editions, plus portions of the other
O'Reilly Perl books), trying this time to get a better grasp of the
fundamentals.

RLH


More information about the Houston mailing list