From: "Weirich, James" Date: 2003-09-13T02:59:42+09:00 Subject: Re: Dir.foreach not with patterns? I like the Dir[] form (or its "glob" alternative). I used to write recursive functions to search a directory tree. Then I discovered Dir['**/*.rb']. Not only is it easier, it's also faster. -- -- Jim Weirich / Compuware -- FWP Capture Services -- Phone: 859-386-8855 > -----Original Message----- > From: dblack@superlink.net [mailto:dblack@superlink.net] > Sent: Friday, September 12, 2003 1:44 PM > To: ruby-talk@ruby-lang.org > Subject: Re: Dir.foreach not with patterns? > > > Hi -- > > On Sat, 13 Sep 2003, Kurt V. Hindenburg wrote: > > > Why does the third one not work as expected? It appears that > > Dir.foreach will not work with patterns... > > > > #!/usr/bin/ruby > > > > s = "/etc/host*" > > > > #1 > > l = Dir[s] > > p l > > > > #2 > > Dir.foreach("/etc") { |d| p d } > > > > #3 > > Dir.foreach(s) { |d| p d } > > > > #4 > > # This is wasteful > > l = Dir[s] > > l.each { |f| p f } > > You don't need two lines, though -- you can do this in a way > that's actually > shorter than #3: > > Dir[s].each {|f| p f} > > > David > > -- > David Alan Black > home: dblack@superlink.net > work: blackdav@shu.edu > Web: http://pirate.shu.edu/~blackdav > >