Chinaunix首页 | 论坛 | 博客
  • 博客访问: 498457
  • 博文数量: 143
  • 博客积分: 4072
  • 博客等级: 上校
  • 技术积分: 1442
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-20 19:27
文章分类

全部博文(143)

文章存档

2014年(2)

2011年(4)

2010年(1)

2009年(9)

2008年(34)

2007年(93)

我的朋友

分类:

2007-02-21 11:50:03

 

1、如果要在WEB页面访问PERL,需要在输出头加上如下行:
print "Content-type: text/plain; charset=iso-8859-1\n\n";
 或
 
如果头是#!/bin/sh
则输出头为
 
# disable filename globbing
set -f  #这里似乎可用中不用,但不清楚为什么
echo "Content-type: text/plain; charset=iso-8859-1"
echo
 
2、语句中换行,则显示为直接换行
3、命令与语句间空行没关系的,只要合法,以分号结束为一句语句的结束
4、双引号与单引号
双中可引用转义字符(interpolate),而单引号直接显示转义字符标识。
变量以$开头
*数值不需要用引号
5、Array:represents a lot of values;
eg: 
    @animals = ("camel", "llama", "owl");
    @numbers = (23, 42, 69);
    @mixed   = ("camel", 42, 1.23);
 
*变量:”$#array“ tells you the index of the last element of an array,这里也可以用来表示
$mixed[$#mixed];  这里返回1.23
*变量:“$#array + 1”to tell you how many items there are in an array;给出数组中的元素个数。
*数组分割:eg
    @animals[0,1];                  # gives ("camel", "llama");
    @animals[0..2];                 # gives ("camel", "llama", "owl");
    @animals[1..$#animals];         # gives all except the first element
*其它用法:
    @sorted    = @animals;
    @backwards = @numbers; 
 
*@ARGV@_变量的使用
 @ARGV是为运算符<> 准备的,用于命令行,此数组的内容为打开过的文件handle;此运算符如果没有参数,则其默认变量为@ARGV上次打的handle。{这个说明还不算太明白}
@_用于子function,表示参数,在定义一个FUNCTION过程中,未给定参数名称,调用它时又给定了参数,则@_[0...n],可以用于代表其值。

eg

    sub max {
$max = (@_);
foreach $foo (@_) {
    $max = $foo if $max < $foo;
}
$max;
    }
    $bestday = max($mon,$tue,$wed,$thu,$fri);

 
6、hash:表系统列的key/value组成,两个值才表示
定义:my %fruit_color
例:
%fruit_color = ("apple", "red", "banana", "yellow");等价于
    %fruit_color = (
        apple  => "red",
        banana => "yellow",
    );
获取其中key与value的方法: You can get at lists of keys and values with and .
     @fruits =  %fruit_colors;
     @colors =  %fruit_colors;
此类型的特例:%ENV 包含些环境变量
一个包含三种类型的较为复杂的变量$,@,%
    my $variables = {
        scalar  =>  {
                     description => "single item",
                     sigil => '$',
                    },
        array   =>  {
                     description => "ordered list of items",
                     sigil => ,
                    },
        hash    =>  {
                     description => "key/value pairs",
                     sigil => '%',
                    },
    };
 
7、Variable scoping
之前的变量定义前均有加my,这个不是必须的。但是如前面使用了use strict,则必须加。
关于变量就学习到这里,下一章节将学习条件语句
阅读(1083) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~