Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Just a few nit-picks to add on top of (well, below) the other replies:
  • When the user happens to enter a command-line arg that is not a usable directory name, nothing happens -- not even an error message to the user saying something like "you were supposed to supply a directory path". A little error checking might help.

  • If you decide to stick with symlinks (rather than merlyn's suggestion of hard links), you could use the perl-internal "symlink" function, instead of shelling out to "ln -s" -- that can save some time, if you end up making a lot of links. (Update: of course, you first have to use "unlink" on the file being replaced, but I'd expect these two calls together are still cheaper than a whole backtick subprocess.)

  • You are doing too many stat calls. You could get by just stat'ing each file once, re-using the stat structure as needed, and keeping info you want to use later; if the loop in the "files()" sub goes like this:
    for $f (grep { ! ( /^\.{1,2}$/ or -l "$path/$_" ) } readdir(DIR)) { if ( -f _ ) { push @files, "$path/$f " . -s _; elsif ( -d _ ) { push @files, @{&files( "$path/$f" )}; } }
    then you have just one stat per file, and the map block in the caller would just be "split" instead of yet another round of stat calls. (perldoc -f stat explains about using the underscore to refer to "the existing stat structure")

    Final update: these really are very minor issues -- they could be "optimizations" in some situations, but probably won't make a noticeable difference in how fast this app goes, given that most of the run time will be spent comparing file contents. Still, if it's easier to write code that runs a little faster, why not write it that way?


    In reply to Re: Identical Files to Symbolic Links by graff
    in thread Identical Files to Symbolic Links by PetaMem

    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: (5)
As of 2024-03-29 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found