博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在 Ruby 当中使用 STDIN(.gets) 循环读取外部文件行并进行处理
阅读量:4229 次
发布时间:2019-05-26

本文共 655 字,大约阅读时间需要 2 分钟。

# test.rb#!/usr/bin/env rubywhile (line = STDIN.gets)  line.chomp!  next unless line =~ /^Hello\s+(\w+)/i        puts "name: #{$1}"end
# test.txthello worldHello Lookingdfdhello Jack
[root@master ruby_learning]# cat test.txt | ruby test.rbname: worldname: Lookingname: Jack

-----------------------------------------------------------------------------------------------------------------

# test.rb#!/usr/bin/env rubywhile (line = gets)  line.chomp!  next unless line =~ /^Hello\s+(\w+)/i        puts "name: #{$1}"end
# test.txthello worldHello Lookingdfdhello Jack
[root@master ruby_learning]# ruby test.rb test.txt      name: worldname: Lookingname: Jack

 

转载地址:http://unjqi.baihongyu.com/

你可能感兴趣的文章
Struts: The Complete Reference
查看>>
Complex IT Project Management: 16 Steps to Success
查看>>
Project Risk Management Guidelines : Managing Risk in Large Projects and Complex Procurements
查看>>
SQL for Microsoft Access
查看>>
Visual Basic 2005 Express: Now Playing
查看>>
Jakarta Struts Cookbook
查看>>
AspectJ Cookbook
查看>>
IntelliJ IDEA in Action
查看>>
HTML Professional Projects
查看>>
Python Cookbook, Second Edition
查看>>
Java Extreme Programming Cookbook
查看>>
XSLT Cookbook
查看>>
Java Programming with Oracle JDBC
查看>>
XML, XSLT, Java, and JSP: A Case Study in Developing a Web Application
查看>>
Java Data Access: JDBC, JNDI, and JAXP
查看>>
Using Moodle
查看>>
Concepts, Techniques, and Models of Computer Programming
查看>>
Skills for Managing Rapidly Changing It Projects
查看>>
Designing a Data Warehouse : Supporting Customer Relationship Management
查看>>
The Tomes of Delphi: Algorithms and Data Structures
查看>>