Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1563544
  • 博文数量: 289
  • 博客积分: 11086
  • 博客等级: 上将
  • 技术积分: 3291
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-22 17:06
个人简介

徐小玉的博客。

文章分类

全部博文(289)

文章存档

2023年(6)

2022年(1)

2021年(2)

2020年(9)

2019年(9)

2018年(6)

2017年(10)

2016年(10)

2014年(3)

2013年(4)

2011年(12)

2010年(16)

2009年(14)

2008年(119)

2007年(48)

2006年(20)

我的朋友

分类:

2010-06-23 11:25:57

第一章:

1: 查看某个函数的用法:
perldoc -f localtime
2: htlm 文件的perl. 很全很详细。
   C:\Perl\html\index.html
  
3:词典:
 1: syntax [sintAks] 语法
 
 
 
 ****************************************
 
 第二章:
 
 1: Predefined Variables :
  $_ The default input and pattern-searching space.
  $. Current line number for the last filehandle accessed.
  $@ The Perl syntax error message from the last eval() operator.
  $! Yields the current value of the error message, used with die.
  $0 Contains the name of the program being executed.
  $$ The process number of the Perl running this script.
  $PERL_VERSION / $^V The revision, version, and subversion of the Perl interpreter.
  @ARGV Contains the command-line arguments.
  ARGV A special filehandle that iterates over command-line filenames in @ARGV.
  @INC Search path for libarary files.
  @_ Within a subroutine the array @_ contains the parameters passed to that subroutine.
  %ENV The hash %ENV contains your current environment.
  %SIG The hash %SIG contains signal handlers for signals.
 
 2: Operators Perl
  Assignment =,  +=,  -=,  *= , %=,  ^=,  &=,  |=,  .=
  Numeric equality = =, !=, <=>
  String equality eq, ne, cmp
  Relational numeric >   >=  < <=
  Relational string gt, ge, lt, le
  Range 5 .. 10 # range between 5 and 10, increment by 1
  Logical &&, and,  ||, or, XOR, xor,  !
  Autoincrement/decrement ++  --
  File -r, -w, -x,-o, -e, -z, -s, -f, -d, -l, etc.
  Bitwise ~  &  |   ^   <<   >>
  String concatenation .
  String repetition x
  Arithmetic * / - + %
  Pattern matching =~, !~
 
 
3: 词典:
Perl comments are preceded by a # sign
backslash sequences (\n, \t, \",   反斜杠...
 
************************************** 
 第三章: Perl scripts
 
 1:  找到 perl interpreter 的位置:(也就是程序开头 shbang line 后面要写的内容: #! /usr/bin/perl )
   which perl
   (or : find / -name '*perl' -print;
  
2:检查脚本是否有语法错误:
    $ perl -c scriptname
   执行脚本:
   perl scriptname
  
 3: windows  下一般不需要shbang line, 可以设置
        SET PATHEXT=.pl;%PATHEXT%
  
4:  perl at the command line
      perl -e 'print "hello Tina"\n';
   perl -e "print qq/hello Tina\n/;"
  
   -n : 利用这个参数,可以遍例一个文件。 perl 行需要在引号内,这个文件也必须在命令行上写出来:
   perl -ne 'print;' emp.first
   perl -ne 'print if/^Igot/;' emp.first
  
   -c :  检查语法。
  

第四章:Getting a handle on printing

      1: the print function

1.1   print函数用单引号\n \t 一类的符号不会被解释,原样打出来

    如果串用的是单引号,会原样打印出来:

           $now = localtime();

           print 'Today is $now, $name.';

          (output) Today is $now, $name.
    
       
String Literals

Escape Sequences

Descriptions (ASCII Name)

\t

Tab

\n

Newline

\r

Carriage return

\f

Form feed

\b

Backspace

\a

Alarm/bell

\e

Escape

\033

Octal character

\xff

Hexadecimal character

\c[

Control character

\l

Next character is converted to lowercase

\u

Next character is converted to uppercase

\L

Next characters are converted to lowercase until \E is found

\U

Next characters are converted to uppercase until \E is found

\Q

Backslash all following nonalphanumeric characters until \E is found

\E

Ends upper- or lowercase conversion started with \L or \U

\\

Backslash

 

12 几个特殊的符号。预定义的。

                                 __FILE__ __LINE__  文件名,行号:

                                 print "This string contains \t\ttwo tabs and a newline.\n" # Double quotes

                   (Output)

                       This string contain       two stabs and a newline.

         这些特殊的定义还有:                    

         Special Literals

Literal

Description

_ _LINE_ _

Represents the current line number

_ _FILE_ _

Represents the current filename

_ _END_ _

Represents the logical end of the script; trailing garbage is ignored

_ _DATA_ _

Represents a special filehandle

_ _PACKAGE_ _

Represents the current package; default package is main

:在单独的一行上写__END__  代表程序脚本的逻辑结束,之后的任何命令都会被忽略。

1   print "We are on line number ", _ _LINE_ _, ".\n";
2   print "The name of this file is ",_ _FILE_ _,".\n";
3   _ _END_ _

 

4 print ;

  5 __DATA__       #这里用 __END__也可以。

  6 This is a test.

   7 I hope it will be printed.   

 (output):

This is a test.

I hope it will be printed.

练习:

1Use the print function to output the following string:

"Ouch," cried Mrs. O'Neil, "You musn't do that Mr. O'Neil!"

print '"Ouch,"cried Mrs.O\'Neil,"Yout must\'t do that Mr.O\'Neil!"',"\n";

print "*************************************\n";

print "\"Ouch,\"cried Mrs\.O\'Neil,\"Yout must\'t do that Mr\.O\'Neil!\"\n";

 

2Use the printf function to print the number $34.6666666 as $34.67.

printf " The \$34.66666666 is %8.2f\n", 34.6666666;

(output) The $34.66666666 is    34.67

3:

#! /usr/bin/perl

my $mei_time=localtime();

print "Today is $mei_time (use localtime())\n";

print "The name os this PERL SCRIPT is",__FILE__,"\n";

print "Hello. The number we will examine is 125.5.\n";

 

print "The Number in decimal is 125.\n";

print "The following number is taking up 20 spaces and is right justifies.\n";

printf " |%10d|\n",125;

print "My boss just siad,\"Can't you load me \$12.50 for my lunch?\n

I flarly said, \"No Way!\" \n

Good-bye \a \n";

###### FOR 4

     print ;

     __DATA__;

     Life is goos with Perl.

    I have just completed my second exercise!

 

阅读(1140) | 评论(0) | 转发(0) |
0

上一篇:Shell 笔记-即时

下一篇:小结实

给主人留下些什么吧!~~