From: Austin Ziegler Date: 2002-10-22T02:15:25+09:00 Subject: Re: functional Ruby equiv to this perl snippet def load_server_list $server_count = 0 $servers = [] File.open('serverlist.txt').each do |line| next if line =~ /^$/ next if line =~ /^#.*$/ $servers << line.chomp.sub(/\s+#.*$/, '') $server_count += 1 end end load_server_list p $server_count p $servers This has the added ability to remove comments after server names. My sample serverlist.txt contained the following: server1 #server2 server3 #server4 server5 server6 # comment after An alternative implementation that doesn't use global variables is as follows: def load_server_list server_count = 0 servers = [] File.open('serverlist.txt').each do |line| next if line =~ /^$/ next if line =~ /^#.*$/ servers << line.chomp.sub(/\s+#.*$/, '') server_count += 1 end [server_count, servers] end (server_count, servers) = load_server_list p server_count, servers -austin -- Austin Ziegler, austin@halostatue.ca on 2002.10.21 at 13.12.15