Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

The idea behind this script both terrifies, and excites me.

The script itself however frightens me, because there are some edge cases that can have some relaly nasty behavior...

  • There's a risk of some silent catastrophic user error if a person inadvertently attempts to rename two different files to the same file (ie: "a->x and b->x" ... or if they mean to do "a->b and b->a" but they forget to change one and wind up with a->b and b->b). It would be pretty easy to prevent this type of error by doing an "exists" around line #60
  • There's a really bad assumption in your "handle overwriting name changes" ... it will work for a->b and b->a but not any other generalized overlaps like "a->b and b->c". This is because the loop over the keys only checks for the existence of the "target" file as a key in the hash and if it exists it creates a temp file -- but it never looks at the value that "target" had in the hash when moving the tmpfile, it just assumes you wanted a straight swap.
  • Even if you fix the previous bug by using mv($tmpfile, $files{$files{$fname}}); instead of mv($tmpfile, $fname); I still think it's possible you're going to wind up edge cases where things fail depending on what files get processed in -- in particular consider the case of "a->b and b->c and c->a"

I think the only safe way to deal with all of this is that if you detect your $target is already a key in the hash, you need to mv($target,$tmpfile) and then update the hash, ala: $files{$tmpfile} = $files{$target}; delete $files{$target};. It complicates things because you can't do a simple loop over a one time copy of the keys, but that's not a big deal. Just do a "while (keys %files) { $fname = (keys %files)[0]; ...; delete $files{$fname}; }" type flow instead.


In reply to Re: Rename files with $EDITOR by hossman
in thread Rename files with $EDITOR by bumby

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 lurking in the Monastery: (5)
As of 2024-04-20 16:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found