From: dblack@... Date: 2003-09-13T02:44:04+09:00 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