KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
This question is a spin-off from this one . Some history: when I first learned Perl, I pretty much always used glob rather than opendir + readdir because I found it easier. Then later various posts and readings suggested that glob was bad, and so now I pretty much always use readdir . After thinking over this recent question I realized that my reasons for one or the other choice may be bunk. So, I'm going to lay out some pros and cons, and I'm hoping that more experienced Perl folks can chime in and clarify. The question in a nutshell is are there compelling reasons to prefer glob to readdir or readdir to glob (in some or all cases)? glob pros: No dotfiles (unless you ask for them) Order of items is guaranteed No need to prepend the directory name onto items manually Better name (c'mon - glob versus readdir is no contest if we're judging by names alone) (From ysth's answer; cf. glob cons 4 below) Can return non-existent filenames: @deck = glob "{A,K,Q,J,10,9,8,7,6,5,4,3,2}{\x{2660},\x{2665},\x{2666},\x{2663}}"; glob cons: Older versions are just plain broken (but 'older' means pre 5.6, I think, and frankly if you're using pre 5.6 Perl, you have bigger problems) Calls stat each time (i.e., useless use of stat in most cases) Problems with spaces in directory names (is this still true?) (From brian's answer) Can return filenames that don't exist: <p
Tags (comma-separated)
Save Edits
Cancel