ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
wired result
by Cheyne Li other posts by this author
May 8 2008 1:27PM messages near this date
Write Ruby code sentences | Re: wired result
Hey, guys.

I'm a new ruby learner. I'm so stuck on the regular expression part.
The following code is a fuction that passed in 2 strings: ftarget, which
is the location of a file to read; fkey is the key to match in the file.

The function simply does open the file, read each line and try to find
if there is a match fkey.

I tested the

i=0
          line.scan(fkey){|x|i=i+1}
          puts i
          if i> 0
            puts "Found match...\n\r"
          end



def fcmp(ftarget,fkey)
    @argc=ftarget
    puts fkey
    unless ftest(ftarget)
      puts "Invalid File name"
      return false
    end
    File.open(ftarget, 'r') do |f1|
        while line = f1.gets
          puts line
          i=0
          line.scan(fkey){|x|i=i+1}
          puts i
          if i> 0
            puts "Found match...\n\r"
          end
          #return false
        end
    end
  end
-- 
Posted via http://www.ruby-forum.com/.
Thread:
Cheyne Li
Cheyne Li
Che
Michael Linfield
Cheyne Li

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved