加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl print01

发布时间:2020-12-15 21:04:43 所属栏目:大数据 来源:网络整理
导读:#!/user/bin/perl #perl -c scriptname? = check the syntax. #perl -ne 'print;' perl01.pl?? = print the all lines of perl01.pl file. #perl -ne 'print if /^#/' perl01.pl? = only print the beginning of '#' # #[root@station78 ~]# date | perl -ne

#!/user/bin/perl #perl -c scriptname? => check the syntax. #perl -ne 'print;' perl01.pl?? => print the all lines of perl01.pl file. #perl -ne 'print if /^#/' perl01.pl? => only print the beginning of '#' # #[root@station78 ~]# date | perl -ne ' print "Today is $_"; ' #Today is Sun Sep 23 16:05:34 CST 2012 #$_ is the var to save the stdin input from pipe. # #perl redirection: #perl -ne 'print;' < perl01.pl #perl -ne 'print;' perl01.pl? > /tmp/perldisplay # # print "What is your name? n"; chomp($name = <STDIN>);?? #wait you input to var "name". print "Welcome,$name,are you ready to learn Perl now? n"; chomp($response = <STDIN>); $response=lc($response);?? #lowercase function to convert var "response". ####check the input is "yes" or "y",a simple logical if statement. if($response eq "yes" or $response eq "y") { ? print "n Great! Let's get startd learning Perl by example. n"; } else { ? print "n O.K. Try again later. n"; } $now = localtime;? # Use a Perl function to get date and time. print "n $name,you ran this script on $now. n"; print "This string contains tttwo tabs and a newline. n"; ###use backquotes to run the os command print "The date is ",`date`;?? #use os command print "The date is `date`",".n";? $directory=`pwd`; print "nThe current directory is $directory."; ###Using alternative quotes #qq//,qq() ==> "" #q//,q()? ==> '' #qx//,qx()? ==> `` # print 'she cried,"I can't help you!" ',"n"? ; print qq/she cried,"I can't help you!"n/? ; print qq(I need $5.00n); print q/I need $5.00/; print qq(I need $5.00 n); print qq/n/,q/I need $5.00/,"n"; print "The present working directory is ",`pwd`; print qq/Today is /,qx/date/; print "The hour is ",qx{date +%H}; #########pragma #use strict "subs"; #$name = "x"; #print "Hi $x.n"; # #use diagnostics;? #==> diagnose your program. give more prompt for you complie errors. #print "xx"; # #-w ==> means you use warnings # # #########end pragma #perl command format: #[root@station78 perl_example]# perl -e 'print "hello dolly n"' #hello dolly # # print "Hello,to you! n"; $now = localtime(); print "Today is $now. n"; $result = 5 * 4 / 2; print "Good bye. n"; print ("Good bye again. n"); #####print different between single and double quota. print 'This string contains tttwo tabs and a newline. n'; print "n"; print "This string contains tttwo tabs and a newline. n"; #####The script is called perl02.pl and we are on line number 20 #21 #__FILE__ => filename #__LINE__ => line number print "The script is called ",__FILE__," and we are on line number ",__LINE__,"n",?__LINE__,"n"; #####Program to illustrate printing literals print "The price is $100 . n"; print "The price is $100 . n"; print "The price is $",100," .? n"; print "The binary number is converted to: ",0b00011," . n";????? #binary 0bxxxxxxx print "The octal number is converted to: ",0010," . n";????????? #octal 0xxx print "The hexadecimal number is converted to: ",0xF," . n";? #hex print "The unformatted number is ",14.56," . n"; $now = localtime();???? #A perl function $name = "Ellie";??????? # A string is assigned to a Perl variable print "Today is $now,$name. n"; print 'Today is $now,$name. n'; print "n"; #export is below: #The price is? . #The price is $100 . #The price is $100 .? #The binary number is converted to: 3 . #The octal number is converted to: 8 . #The hexadecimal number is converted to: 15 . #The unformatted number is 14.56 . #Today is Sun Sep 23 18:10:40 2012,Ellie. #Today is $now,$name. n ### ###backslash interpretation print "***tIn double quotest***n"; print '%%%ttIn single quotes tt%%%n'; print "n"; print "att The UnumberE LIsE ",".n";? #a=> system beep,t=>tab #U====>E change all char to upper.? L====>E change all char to lower. #__END__? ===> like the ctrl+D and 04 to end the script. print "n"; $_="Donald Duck";?? #default $_ print; print "n"; print "n"; ### #####print data to print serveral rows print <DATA> __DATA__ This line would be printed. And so will this one. Just like shell echo multi-rows.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读