Perl的字符串操作
来源:互联网 发布:淘宝联盟返利 编辑:程序博客网 时间:2024/05/14 23:12
字符串数组元素赋值:@tmp=qw(aaa bbb kkk 9000);相当于@tmp=(“aaa”, “bbb”,“kkk”,“9000);
[macg@localhost perltest]$ vi tip.pl
#!/usr/bin/perl
print"input:";
while(chomp($input=<>)) {
print"your input is $input \n";
if ($input=="q") { print "choose q \n";last;}
print "input:";
input:x
your input is x
choose q
while(chomp($input=<STDIN>))
Argument "" isn't numeric in numeric eq (==) at ./address.pl line77, <STDIN> line 2.
对整形变量$input==$i,如果$input是回车,并不走else,而是报错
while(chomp($input=<STDIN>))
which interface you want to config ? choice a number 1 2 3 4q:1
Do you want to change eth0 's ip address ?
print "純金 ", $v1;
print $str, "\n\n";
print '12345 大家來跳舞' . " hello world";
結果變成:
12345 大家來跳舞 hello world
print "OK" x 4;
結果變成:
OKOKOKOK
因为可能+就是真加了(数字相加),而不是字符串合并
$v1 = 99;
$v2 = '121';
print $v1 + $v2;$v1 = 99;
$v2 = '121';
print $v2 . $v1;22012199
$min=1;
$date="date "."0".$min;
print $date,"\n";
date 01
$str="abCD99e";
$str = uc($str);$str="abCD99e";
$str = lc($str);[macg@localhost perltest]$ ./tip.pl
ABCD99E
abcd99e
#!/usr/bin/perl
$str="abCD99e";
$strlen=length($str);
print $strlen,"\n";[macg@localhost perltest]$ ./tip.pl
7
#!/usr/bin/perl
$str = "ABCDEFG1234567";
$a = substr $str, 0, 5;
print $a,"\n";[macg@localhost perltest]$ ./tip.pl
ABCDE
$a = substr $str, -4,2;
45
#!/usr/bin/perl
$str = "ABCDEFG1234567";
$a ="12";
$pos=index($str,$a);
print $pos,"\n";[macg@localhost perltest]$ ./tip.pl
7
#!/usr/bin/perl
$str = "ABCDEi FG12i 345 6 7";
@array=split(//,$str);按空格分
foreach (@array) {
}
ABCDEi
FG12i
345
6
7
@array = split (/ +/,$line);
[macg@localhost perltest]$ vi tip.pl
#!/usr/bin/perl
$str = "ABCDEiFG12i
@array=split(/\t/,$str);
foreach (@array) {
}[macg@localhost perltest]$ ./tip.pl
ABCDEi FG12i
345 6 7
因为同时满足TAB和空格的只有一处
所以必须加[ ]
@array=split(/[\t]/,$str);
ABCDEi
FG12i
345
6
7
语法:join($string,@array)
@array=qw(one two three);$total="one,two,three";@array=qw(one two three);
$total=join(":",@array);
@array=("one","on","in");
$count=grep(/on/,@array);
查询结果赋值给单变量@array=("one","on","in");
@result=grep(/on/,@array);
查询结果赋值给数组2one
on
Perl里面不能像C语言那样根据下表来操作字符串里面的单个字符,这时候用substr最好,还能操作用下表不好表示的一些俄操作。
- Perl的字符串操作
- perl 字符串操作
- perl 字符串操作
- perl 字符串基本操作
- perl 字符串相关操作
- perl字符串操作符
- Perl字符串基本操作详解
- Perl字符串基本操作详解
- perl字串的操作
- PERL的数组操作
- Perl的目录操作
- Perl 字符串操作 以及 自定义排序
- Perl的字符串构造时机
- perl字符串操作符、system函数及其对系统命令的调用
- 操作excel的perl模块
- perl对数组的操作
- perl对mysql的操作
- Perl操作excel2007的模块
- MSDN库(中文)
- 多么给力的锁啊,呵呵!! 不解释
- Android 按两次back键退出 -- 效率最高版---见到好东西就转啊!
- 文件夹选择对话框的使用
- 从长度为N的数组中找出所有M个元素组合的优化算法
- Perl的字符串操作
- 关于在ODBC中增加数据源的问题
- office插件开发(转)
- Application.MessageBox 详解
- 邻接矩阵存储图的两种遍历方式
- ffmpeg + opencv + pc + arm 完整
- Flex文档API生成工具AsDoc
- verilog入门小结
- shell常用命令2