[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Dir.foreach not with patterns?

Kurt V. Hindenburg

9/12/2003 5:28:00 PM

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 }

--
^^^ Kurt

There is no good nor evil, just power.
1 Answer

nobu.nokada

9/12/2003 5:38:00 PM

0

Hi,

At Sat, 13 Sep 2003 02:28:02 +0900,
Kurt V. Hindenburg wrote:
> Why does the third one not work as expected? It appears that
> Dir.foreach will not work with patterns...

Use Dir.glob.

--
Nobu Nakada