#!/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 \t\ttwo 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.00\n);
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 \t\ttwo tabs and a newline. \n';
print "\n";
print "This string contains \t\ttwo 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 quotes\t***\n";
print '%%%\t\tIn single quotes \t\t%%%\n';
print "\n";
print "\a\t\t The \Unumber\E \LIs\E " ,0010, ".\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 \004 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.
perl print01
原创emperor_majesty 博主文章分类:Perl ©著作权
文章标签 print function 文章分类 运维
上一篇:perl STDIN
下一篇:perl printf

-
01-zabbix安装
centos7上面部署zabbix
mysql vim php -
perl基础知识01【perl用处】
1.什么是perl?2.它用来做什么?3.如何学会它?回
perl SQL 数据库 -
【Python系统学习01】print函数的用法
print函数的用法。类似JS中的console.log函数
学习笔记 python 单引号 双引号 转义字符 -
perl
perl 编码风格:1.K.R2.GNU3.BSD采用K&R
职场 休闲 perl