Perl file list array




















Learn more. How can I list all of the files in a directory with Perl? Asked 12 years, 6 months ago. Active 7 years, 5 months ago. Viewed k times. Improve this question. ScottJShea 6, 11 11 gold badges 43 43 silver badges 66 66 bronze badges.

Paradius Paradius 7, 11 11 gold badges 30 30 silver badges 36 36 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. I always forget that readdir just returns a list of relative filenames, not the entire path! Thanks for discouraging the use of globbing for this task. Another downside of using globbing for this is, that it will not find hidden files those starting with a dot. Matthew Vines Matthew Vines Hi, thanks for the pointer, but it looks like this lists also the files in the current dir, not just the directories.

I modified my question to include my test script, because including it in the comments seems complicated. Example updated. They'll work the same. The only time brackets are mandatory is when there's e. Show 1 more comment. Using glob is easier :- — Dave Cross. DaveCross Well, yes, I agree, of course.

But I thought that there'd every reason to show the other standard method as well. Add a comment. AbhiNickz AbhiNickz 1, 2 2 gold badges 17 17 silver badges 28 28 bronze badges.

Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.

Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. Nathan Campos Nathan Campos Add a comment. Active Oldest Votes. Improve this answer. Corey Corey 1, 9 9 silver badges 12 12 bronze badges. You should check if file was opened successfully. Or use autodie; — Ivan Nevostruev.

Ivan Nevostruev Ivan Nevostruev Thank you. I've never seen that shorthand way of loading and chomping an array at the same time before. One more answer for you to choose from:!

Mark Byers Mark Byers k gold badges silver badges bronze badges. The most basic example looks like this:! So the actual 2nd try is:! Tamas Mezei Tamas Mezei 6 6 silver badges 9 9 bronze badges. There is shortcut for chomp: chomp lines ; — Ivan Nevostruev. Oh, I forgot that.



0コメント

  • 1000 / 1000