设为首页 收藏本站
查看: 1539|回复: 0

[经验分享] Perl 开发的学习-2

[复制链接]

尚未签到

发表于 2018-8-31 13:12:19 | 显示全部楼层 |阅读模式
  字符串变量,需要注意单引号与双引号的不同,这一点在Shell里也一样,就是单引号不进行转义
DSC0000.jpg

  [root@windriver-machine test]# cat str.pl
  #!/usr/bin/perl
  $str="short";
  $string="long";
  print "match longest $string\n";
  print "match shortlets ${str}ing\n";
  [root@windriver-machine test]# perl str.pl
  match longest long
  match shortlets shorting
  [root@windriver-machine test]#
DSC0001.jpg DSC0002.jpg DSC0003.jpg

  root@windriver-machine test]# cat esc.pl
  #!/usr/bin/perl
  print "bell ring:\a\n";
  print "back#\bspace\n";
  print "copy\rabc\n";
  print "abc\tdef\n";
  print "the\$var\n";
  print "a quote \" in string \n";
  print "a quote \\ in string \n";
  print "\045\n";
  print "\x25\n";
  print 'the \$var\n';
  print 'this is the first line,
  this is second line.\n';
  [root@windriver-machine test]# perl esc.pl
  bell ring:
  backspace
  abcy
  abc def
  the$var
  a quote " in string
  a quote \ in string
  %
  %
  the \$var\nthis is the first line,
  this is second line.\n[root@windriver-machine test]#
DSC0004.jpg

  [root@windriver-machine test]# cat qq.pl
  #!/usr/bin/perl
  $var=1;
  print q(the $var\n);
  print qq(is $var\n);
  print qq;
  [root@windriver-machine test]# perl qq.pl
  the $var\nis 1
  string "str"(var) in qq[root@windriver-machine test]#
DSC0005.jpg

  [root@windriver-machine test]# perl undef.pl
  2
  [root@windriver-machine test]# cat undef.pl
  #!/usr/bin/perl
  $r=$und+2;
  print "$r\n";
  [root@windriver-machine test]#
  [root@windriver-machine test]# cat undef.pl
  #!/usr/bin/perl -w
  $r=$und+2;
  print "$r\n";
  [root@windriver-machine test]# perl undef.pl
  Name "main::und" used only once: possible typo at undef.pl line 2.
  Use of uninitialized value in addition (+) at undef.pl line 2.
  2
  [root@windriver-machine test]#
DSC0006.jpg

DSC0007.jpg

DSC0008.jpg

  root@windriver-machine test]# cat chp.pl
  #!/usr/bin/perl
  $a="abcd";
  chop($a);
  print "chop $a\n";
  $a="abcd";
  chomp($a);
  print "chomp $a\n";
  $a="abc\n";
  chop($a);
  print "chop $a|";
  $a="abc\n";
  chomp($a);
  print "chomp $a|";
  $a="abc\n\n\n";
  $/="";
  chomp($a);
  print "chomp many $a\n";
  $/="cd";
  $a="abcd";
  chop($a);
  print "chop $a|";
  $a="abcd";
  chomp($a);
  print "chomp $a|";
  [root@windriver-machine test]# perl chp.pl
  chop abc
  chomp abcd
  chop abc|chomp abc|chomp many abc
  chop abc|chomp ab|[root@windriver-machine test]#
  注意这些函数是直接修改原变量,不是返回值。
DSC0009.jpg

  操作符与操作数是计算机里的基本的概念,同样在Perl 中也一样。
DSC00010.jpg

DSC00011.jpg

DSC00012.jpg

DSC00013.jpg

DSC00014.jpg

DSC00015.jpg

  移位运算首先操作符一定是整数,否则是无法进行移位操作的。
DSC00016.jpg

DSC00017.jpg

DSC00018.jpg DSC00019.jpg

DSC00020.jpg

DSC00021.jpg

DSC00022.jpg

  [root@windriver-machine test]# cat op.pl
  #!/usr/bin/perl
  print " minus the number before pot:";
  $a=25.7%7.6;
  print "$a\n";
  print "log number is pot:";
  $b=(25)**1.5;
  print "$b\n";
  print "auto increment for string,donot extrand length:";
  $a='Z';
  $a++;
  print "$a\n";
  print "the prority of || and or is not same:\n";
  $a=1;
  $b=1;
  $c=($a+=0||$b);
  print "$c\n";
  $a=1;
  $b=1;
  $c=($a+=0 or $b);
  print "$c\n";
  print "=associativity :";
  $a=2,$b=1;
  $a*=$b+=5;
  print "$a\n";
  $a=2,$b=1;
  ($a*=$b)+=5;
  print $a;
  [root@windriver-machine test]# perl op.pl
  minus the number before pot:4
  log number is pot:125
  auto increment for string,donot extrand length:AA
  the prority of || and or is not same:
  2
  1
  =associativity :12
  7[root@windriver-machine test]#
DSC00023.jpg



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-559407-1-1.html 上篇帖子: perl学习总结之引用 下篇帖子: perl中的几个模块使用.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表