
| [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:"; |
| [macg@localhost perltest]$ ./tip.pl input:x your input is x choose q |
| while(chomp($input=<STDIN>)) |
| Do you want to change eth0:2 's ip address ? 回车 Argument "" isn't numeric in numeric eq (==) at ./address.pl line 77,<STDIN> line 2. 对整形变量$input==$i,如果$input是回车,并不走else,而是报错 |
while(chomp($input=<STDIN>))
which interface you want to config ? choice a number 1 2 3 4 q: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; |
| 220 | 12199 |
| $min=1; $date="date "."0".$min; print $date,"\n"; |
| [root@ntracker mac]# ./tip.pl date 01 |
| $str="abCD99e"; $str = uc($str); | $str="abCD99e"; $str = lc($str); |
| [macg@localhost perltest]$ ./tip.pl ABCD99E | [macg@localhost perltest]$ ./tip.pl 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,5; print $a,sans-serif; line-height: 18px; ">[macg@localhost perltest]$ ./tip.pl ABCDE |
| $a = substr $str, -4,2; |
| [macg@localhost perltest]$ ./tip.pl 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) { } |
| [macg@localhost perltest]$ ./tip.pl ABCDEi FG12i 345 6 7 |
@array = split (/ +/,$line);
| [macg@localhost perltest]$ vi tip.pl #!/usr/bin/perl $str = "ABCDEi FG12i @array=split(/\t /,$str); foreach (@array) { } |
| [macg@localhost perltest]$ ./tip.pl ABCDEi FG12i 345 6 7 |
因为同时满足TAB和空格的只有一处
所以必须加[ ]
| @array=split(/[\t ]/,$str); |
| [macg@localhost perltest]$ ./tip.pl 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); | $total="one:two:three"; |
| @array=("one","on","in"); $count =grep(/on/,@array); 查询结果赋值给单变量 | @result=grep(/on/,@array); 查询结果赋值给数组 |
| 2 | oneon |
以上是内存溢出为你收集整理的perl 字符串 *** 作全部内容,希望文章能够帮你解决perl 字符串 *** 作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)