Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Dir Tree in Perl

by afoken (Chancellor)
on Nov 04, 2012 at 21:16 UTC ( [id://1002244]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Dir Tree in Perl
in thread Dir Tree in Perl

im trying to avoid using cpan for this project

Bad idea. Your code is also sub-optimal:

  • use strict missing
  • & in front of function calls does not do what you think. Get rid of it, this ain't ancient Perl 4.
  • local instead of my
  • Recursion in loopDir will eventually run out of handles. Collect all subdirectories, then recurse after closing the directory handle. Or use a directory queue (shift the directory to read from, push every new directory found, run until queue is empty) and completely get rid of the recursion.
  • close (MYFILE) is unreachable due to exit in front of it
  • Two-argument open instead of three-argument open. Do you really need to support perl < 5.6 (more than twelve years old)?
  • Bareword file handles instead of lexical ones
  • open || die instead of open or die, same problem with chdir
  • die without an error message ($!)
  • opendir lacks an error check.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1002244]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-04-23 18:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found