Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Once upon a time, about three years ago, I was writing a script to generate a large set of flat data files from a set of databases. The script was pretty straightforward: Fetch some data, munge it, write out the files into a series of directories. The directory tree would have been three levels deep with 16 nodes at each level and 16 files in each directory at the bottom level. In other words, about 65,536 files. I ran my program, but it had a crucial bug: It was not changing back to the root directory of the tree on each iteration! By the time I realized what had gone wrong and stopped the program, I had a directory structure several thousand levels deep.

Naturally, I first attempted to rm -rf it. That didn't work; rm complained that the structure was too deep and couldn't be traversed recursively. (I have since forgotten the exact error message and I didn't particularly feel like re-creating the situation.)

I tried piping find to xargs, but even that wouldn't work because rm would not delete a non-empty directory and find would fail before reaching the bottom. I tried any number of other solutions suggested by people on IRC and random friends over IM, without any luck.

I called over the several BSD and shell experts at my office and sheepishly admitted what I had done, and asked their advice. One said the filesystem was hosed and I would have to reinstall the system. (Not an ideal solution as this was a large server used by many.) Another tried a few shell tricks but also couldn't fix it.

I finally decided that if Perl could create this mess, Perl must be able to fix it. I wrote a simple Perl version of rm -rf -- traverse the directories recursively and unlink the files at the end of the tree. I ran it and, lo and behold, it worked. After just a couple minutes, my bottomless directory tree of hell was gone. Perl didn't complain at all. Perl didn't even flinch.

Perl is cool.


In reply to Your Favorite Heroic Perl Story by friedo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-03-28 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found