关于perl中如何实现switch结构
来源:互联网 发布:java gui 程序设计pdf 编辑:程序博客网 时间:2024/04/29 10:13
众所周知,perl中没有内置的switch结构,但是switch确实很有用,它提供了一个简单明了的结构体,可以避免烦琐的if else。既然perl不支持switch结构,我们可以自己写一个switch结构。我的switch结构如下:
print("Enter command:");
while(<>)
{
SWITCH:{
/run/ && do{
print("match:".$_."/n");
last SWITCH;
};
/q/ && do{
print("match:".$_."/n");
exit;
};
DEFAULT: $message = "No match:$_/n";
print($message."/n");
}
print("Enter command:");
}
实现机制很简单,就是添加一个SWITCH标签,在SWITCH中以模式匹配的方式来实现case语句。
last SWITCH是退出当前SWITCH语句块儿。
Sylvester
youhaodeyi@gmail.com
- 关于perl中如何实现switch结构
- Python中switch结构的实现
- perl中没有switch可以采用hash一样来实现
- python switch结构的实现
- 关于switch语句中使用String类型的实现原理
- 在SQL中如何实现类似C#的switch语句
- python中实现switch
- 用switch语句实现多分支结构
- switch语句实现多分支结构
- Python实现类似switch的分支结构
- java语言中Switch 结构的用法
- 如何在ZFS中实现RAID结构
- Python中switch-case实现
- python 中switch的实现
- Python中实现switch功能
- perl笔记-----switch
- Switch结构
- switch结构
- 进程、线程调度模型及其在Windows2000中的实现
- 仍然活着
- Nuva 示例代码(每日一帖)之 国际化界面
- 父字
- UBUNTU安装及优化手记
- 关于perl中如何实现switch结构
- 什么是IPS?
- 编写云台控制程序
- Eclipse下配置spring应用
- Web Services 的dataTable问题
- 学习c++的50条忠告
- 下列语句部分是Mssql语句,不可以在access中使用。
- 我是幸福的
- 为DataGridView增加日期/时间列