关于编程学习的方面,请达人帮忙。万分感谢

关于编程学习的方面,请达人帮忙。万分感谢,第1张

◎字串运算子

String Operator Purpose

x Returns a string consisting of the string on the left of the operand, repeated the number of times of the right operand.

. Concatenates the two strings on both sides of the operator.

eq Returns True if the two operands are equivalent, False otherwise.

ne Returns True if the two operands are not equal, False otherwise.

le Returns True if the operand on the left is stringwise less than the operand on the right of the operator. Returns False otherwise.

lt Returns True if the operand on the left is stringwise less than or equal to the operand on the right of the operator. Returns False otherwise.

ge Returns True if the operand on the left is stringwise greater than or equal to the operand on the right of the operator. Returns False otherwise.

gt Returns True if the operand on the left is stringwise greater than the operand on the right of the operator. Returns False otherwise.

cmp Returns -1, 0, or 1 if the left operand is stringwise less than, equal to, or greater than the right operand.

, Evaluates the left operand, the evaluates the right operand. It returns the result of the right operand.

++ Increments the string by one alphabetic value.

◎数值运算子

Value Operator Purpose

+ Computes the additive value of the two operands.

- Computes the difference between the two operands.

* Computes the multiplication of the two operands.

/ Computes the division between the two operands.

% Computes the modulus(remainder) of the two operands.

= = Returns Ture if the two operands are equivalent, False otherwise.

!= Returns Ture if the two operands are not equal, False otherwise.

<= Returns Ture if the operand on the left is numerically less than or equal to the operand on the right of the operator. Returns False otherwise.

=>Returns Ture if the operand on the left is numerically greater than or equal to the operand on the right of the operator. Returns False otherwise.

<Returns Ture if the operand on the left is numerically less than the operand on the right of the operator. Returns False otherwise.

>Returns Ture if the operand on the left is numerically greater than the operand on the right of the operator. Returns False otherwise.

<= >Returns -1 if the left operand is less than the right, +1 if is it greater than, and 0(False) otherwise.

&&Performs a logical AND operation. If the left operand is True m then the right operator is not evaluated.

|| Performs a logical OR operation. If the left operand is True m then the right operator is not evaluated.

&Returns the valueof the two operators bitwise ANDed.

| Returns the valueof the two operators bitwise ORed.

^ Returns the valueof the two operators bitwise XORed.

++ Increment operator. Increments the variable's value by 1.

-- Decrement operator. Decrements the variable's value by 1.

** Computes the power of the left-hand value to the power of the rihght-hand value.

+= Adds the value of the right-hand operand to the value of the left-hand operand.

-+ Subtracts the value of the right-hand operand to the value of the left-hand operand.

*= Mlutiplies the value of the left-hand operand to the value of the right-hand operand.

>>Shifts the left operand right by the number of bits that is specified by the right operand.

<<Shifts the left operand left by the number of bits that is specified by the right operand.

~ Performs a 1s complement of the operator. This is a unary operator.

(b) Scalar Array:

纯量阵列,阵列内的每一个元素都是Scalar variable。宣告及使用方式如下:

# 纯量阵列以 @ 开头。

my @array

my @array=qw(a b c d)

# qw 函数会将其后的每个元素用逗点隔开,效果就像下面这行。

my @array=("a","b","c","d")

# 当然你也可以一个个元素宣告,下面就是存取每一个元素的方法。

# 因为阵列中的每一个元素都是纯量变数,所以要以 $ 开头,

# 刚开始容易搞混,请注意。

$array[0]="a"$array[1]="b"$array[2]="c"$array[3]="d"

# 使用for loop印出阵列内每个元素的值。

for($i=0$i<=$#array$i++) {

print "$array[$i]\n"

}

看到$#array这个奇怪的东东没? 这是Perl的一个特殊用法,代表这个阵列最后一个元素的注标。由於Perl不必事先宣告变数,也不必预先宣告阵列的大小,甚至可以随时增加新元素,那我们怎麼知道这个阵列到底有多大呢? 透过这个特殊变数我们可以得知这个这个阵列最后一个元素的注标,自然而然也就知道这个阵列究竟有多大了。另外Perl只定义了一维阵列的语法,二维以上只能用指标间接来达成。

(c) Hash Array(Associative Array):

杂凑阵列也叫做相关阵列,它和一般阵列没什麼不同,差别只是在它的索引值用的是字串,而非一般阵列所用的整数值,因此相关阵列不像一般阵列一样有次序的概念,它没有所谓的第一项资料这种说法。它就相当於把一堆变数组合成一个group,然后我们可以透过索引字串存取这个group每一个元素的值。相关阵列的宣告及使用方式如下:

# 相关阵列是以 % 符号开头的。

my %hash

# =>这个符号是Perl5新增的,是为了相关阵列量身定做的,

# 因为索引和元素值都是纯量,若使用 =>这个符号,

# (索引=>元素值) 两两对应,就不容易发生失误。

my %hash=("i1"=>"aaa","i2"=>"bbb","i3"=>"ccc")

# 上面这行的效果和下面这行是一样的。

my %hash=("i1","aaa","i2","bbb","i3","ccc")

# 下面是存取每个元素的方法,注意是用大括号把索引括起来哦。

# 习惯上索引值用单引号、元素值用双引号括起来。

$hash{'i1'}="aaa"$hash{'i2'}="bbb"$hash{'i3'}="ccc"

# 下面是使用相关阵列的三个例子:

foreach $key (keys %hash) {

print "$hash{$key}\n"

}

foreach $value (values %hash)

while(($key,$value)=each %hash)

Perl有上述三个函数可对相关阵列做运算:keys函数可取出相关变数的索引值,组成一纯量阵列,注意这些由keys函数取出的索引值没有次序性;values函数可取出相关变数的元素值;each函数则会取出(索引、元素)对。使用者可视情况而用。

(d) References(Pointer):

Perl 5新增了参考指标的资料型态,使Perl和C一样可借由指标建立一些复杂的资料结构。普通程式是用不到指标这玩意的,下面也只是简单介绍一下,看不懂的人可不必深究。

⊙如何取得变数的位址?

$scalarRef=\$scalarVar

$arrayRef=\@arrayVar

$hashRef=\%hashVar

$funcRef=\&funcName

⊙如何使用指标?

print $$scalarRef

print "@$arrayRef"

print $hashRef->{$key}

&$funcRef

⊙Anonymous Array References:(二维阵列)

$arrayRef=[[1,2,3,4],a,b,[x,y,z],c]

print "$arrayRef->[0][0]\t$arrayRef->[2]\t$arrayRef->[3][2]\n"

⊙Anonymous Hash References:

$hashRef={a=>aa,b=>bb,c=>cc}

print "$hashRef->{a}\t$hashRef->{b}\t$hashRef->{c}\n"

(2) 控制叙述(Control Statements)

(a) Conditional Control Statements:

Perl的条件控制叙述和C语言很像,让使用者很快就能掌握它。不过Perl比C语言又另外多了些实用的语法,我用底线标出来,大家一看便知:

# Expression 就是条件叙述式,Perl和C一样没有定义布林资料型态(Boolean data type),

# 因此 0 是false、非0 是ture。另外要注意字串运算子和数值运算子要分清楚哦。

# Code Segment 就是用大括号括起来的一堆指令,也就是一个Block。

if (Expression) {Code Segment}

if (Expression) {Code Segment} else {Code Segment}

if (Expression) {Code Segment} elsif (Expression) {Code Segment} else {Code Segment}

# elsif 就是 else if

# 如果指令(statement)只有一项,我们可以使用倒装句法,看起来比较简洁。

statement if (Expression)

# unless 就是if not

statement unless (Expression)

例:

print "HELLO!\n" if ($name eq "friend")

$x-=10 if ($x == 100)

看吧! C 语言有的Perl大部分都有,学过 C 的人可以毫不费力的学会Perl。

(b) Loop Control Statements:

Perl的回圈控制叙述也和C语言很像,当然,照例Perl也另外多了些实用的语法:

# 注意:纯量变数前面要加个 $ 字号,这一点和C语言不一样哦。

for($i=0$i<=10$i++) {Code Segment}

# foreach 是承袭UNIX的shell script来的,

# 第一个引数是纯量变数,第二个引数要用括号括起来,里面是一个纯量阵列,

# 顾名思义它就是把阵列中的每个元素依序传给第一个引数,直到全部传完。

# 它和 for($i=0$i<=$#array$i++) 用法虽然不同,但目的都是要取出阵列的每个元素。

foreach $i (@array) {Code Segment}

# 其实在Perl中,for和foreach是可以混著用的,就看个的人习惯了。

# 下面这行就等於上面第一个叙述,不过简洁多了,大家可以试著用用看。

for $i (0..10) {Code Segment}

# while控制回圈和后置回圈。

while($i<=10) {Code Segment}

do {Code Segment} while(Expression)

# Perl也有和C语言的break和continue一样的指令,Perl叫它做 last 和 next (较口语化)。

# last是跳出现在所在的回圈,next则是跳过下面的指令直接执行下一次的回圈。

while(chomp($i=<STDIN>)) {

next if ($i == 5)

last unless ($i >10)

}

Perl还有提供label(标记)的语法,也就是 goto 指令,不过有经验的programer并不喜欢用它,我也不建议大家使用,所以就此按下不讲。有兴趣的人请自行查阅。还有一点值得注意的是Perl没有提供像C语言一样的 switch 叙述,不过Perl的pattern match的功能非常强,所以我建议你直接用 if else 叙述来做就好了。

(3) 副程式(Subroutines)

(a) Syntax: sub NAME {Code}

(b) 呼叫副程式: &NAME(para1, para2,...)

(c) 参数传递: @_

Perl和C一样是采用Call by value的方式,不过因为Perl不用事先宣告变数,所以建立副程式的时候也不用宣告要传递什麼参数。当主程式在传递参数给副程式时,Perl会把括号括起来的参数按顺序放在一个特殊的全域变数 @_ 阵列中,然后副程式就可以随意使用阵列 @_ 里的参数,例如 $_[0] 是第一个参数, $_[1] 是第二个,或是用 my ($a1,$a2,$a3,...) = @_来取出各个参数,当然 my @arg=@_或 my %arg=@_也是可以的。由於Perl的语法非常活泼,使得程式在维护时特别棘手,因此写注解成为一项很重要的工作。我建议你最好在每个副程式前面加上对这段副程式的描述,特别是需要传递的参数要注明清楚。

(d) Variable Localization:my or local

通常我们在程式中定义的变数都是全域变数,所以在副程式中若要把变数区域化则要加上 my 或 local 关键字,例如: my $x=3,若副程式所用的变数名不小心和主程相同,Perl会以目前正在执行的副程式里的变数为优先。

(4) I/O和档案处理

(a) Syntax:

open(FILEHANDLE,"Expression")

close(FILEHANDLE)

这里的Expression是一个叙述加上档案名称,若Expression只有档案名称没有加上叙述,则预设是唯读。Expressions叙述如下:

Expression Effect

open(FH, "<filename") Opens filename for reading.

open(FH, "+<filename") Opens filename for both reading and writing.

open(FH, ">filename") Opens filename for writing.

open(FH, "+>filename") Opens filename for both reading and writing.

open(FH, ">>filename") Appends to filename.

open(FH, "command|") Runs the command and pipes its output to the filehandle.

open(FH, "command|") Pipes the output along the filehandle to the command.

open(FH, "-") Opens STDIN.

open(FH, ">-") Opens STDOUT.

open(FH, "<&=N") Where N is a number, this performs the equivalent of C's fdopen for reading.

open(FH, ">&=N") Where N is a number, this performs the equivalent of C's fdopen for writing.

例:

# 开启$filename这个档案,若开启失败则印出die后面的讯息,并结束程式。

open(FILE, $filename) || die "Can't open file $filename : $!\n"

# 下面是一个十分精简的写法,和 while($_=<FILE>){print "$_"} 是等效的。

print while(<FILE>)

# 档案开启后要记得随手关闭,这才是写程式的好习惯。

close(FILE)

# $!和$_都是Perl的特殊变数,下面会介绍的。

(b) Input:

Perl没有特别用来输入的函数,因为Perl在执行程式时,会自动开启标准输入装置,其filehandle定为STDIN,所以在Perl中要输入资料的方法就是使用<STDIN>:

# Perl不会自动去掉结尾的CR/LF,跟C语言不同,所以要用chomp函数帮你去掉它。

# 大家常常会忘记这个动作,导致结果跟你想的不一样,要特别注意一下。

$input=<STDIN>chomp $input

# 下面是较简洁的写法。

chomp($input=<STDIN>)

(c) Output: print "variables or 字串"

Perl也有printf()函数,语法和C语言一模一样,我就不多做介绍了。Perl另外有个print函数,比printf()更方便、更好用,包你爱不释手。 Output不外乎是输出到萤幕或档案,用例子来说明比较容易了解。

# 不用再指定变数的data type,这样不是比printf()方便多了吗?

print "Scalar value is $x\n"

# . 是字串加法的运算子,上下这两行是等效的。

print "Scalar value is " . $x . "\n"

# 输出到档案的方法。

print FILE "print $x to a file."

# 下面是print的特殊用法,学自shell script的用法:

print<<XXX

这招叫做 here document,XXX可以是你取的任何识别字,

在识别字之间的字都会按照你所写的样子输出,就像<pre>标签一样。

而当一行的开头是XXX你取的这个识别字时,才会停止输出。

XXX

Perl 也有和 C 一样以 "\" 开头的特殊字元:

\ttab

\nnewline

\rreturn

\fform feed

\bbackspace

\aalarm(bell)

\eescape

\033 octalchar

\x1b hex char

\c[ control char

\llowercase next char

\uuppercase next char

\Llowercase till \E

\Uuppercase till \E

\Eend case modification

\Qquoteregexp metacharacters till \E

另外需要说明的是 Perl 融合了 unix shell script 的使用惯例,以双引号("")括起来的字串会先经过展开,但反斜线(\)后面的字元则不展开,当作一般字元看待。而以单引号('')括起来的字串完全不会展开,以反单引号(``)括起来的字串会把它当作命令列指令一样执行,等於system()一样。初学者常常会搞混,但习惯之后就会觉得不这样分清楚反而不行哩。举个例吧:

$x="ls -l"

print "$x"# Output ls -l

print "\$x" # Output $x

print '$x'# Output $x

print `$x`# Output files in this directory

(5) Regular Expressions

Regular Expression通常是用来寻找特定的字串样式(pattern),也就是所谓格式辨认(pattern-matching)的功能。它的运算子是『=~』和『!~』,可以把它念做match和not match。

Syntax: $string =~ /regular expression/expression modifier

例:$sentence =~ /Hello/

当你有大量的数据需要管理的时候,就需要用到数据库。

而你需要提供给 *** 作人员一个良好的数据处理界面,就要涉及到数据库开发。

比如一个工厂生产线上产品的处理过程。

数据库开发不仅仅是写存储过程,函数,触发器。包括很多内容。

1.掌握数据库技术的基本概念、原理、方法和技术;

2.能够使用SQL语言实现数据库 *** 作;

3.具备数据库系统安装、配置及数据库管理与维护的基本技能;

4.掌握数据库管理与维护的基本方法;

5.掌握数据库性能优化的基本方法;

6.了解数据库应用系统的生命周期及其设计、开发过程;

7.熟悉常用的数据库管理和开发工具,具备用指定的工具管理和开发简单数据库应用系统的能力;

8.了解数据库技术的最新发展。

一、数据库应用系统分析及规划

1.软件工程与软件生命周期。

2.数据库系统生命周期。

3.数据库开发方法与工具。

4.数据库应用体系结构。

5.数据库应用接口。

二、数据库设计及实现

1.概念设计。

2.逻辑设计。

3.物理设计。

4.数据库对象实现及 *** 作。

三、数据库存储技术

1.存储与文件结构。

2. 索引技术。

四、并发控制技术

1.事务管理。

2.并发控制技术。

3.死锁处理。

五、数据库管理与维护

1、数据完整性。

2、数据库安全性。

3、数据库可靠性。

4、监控分析。

5、参数调整。

6、查询优化。

7、空间管理。

六、数据库技术的发展与新技术

1、分布式数据库。

2、对象数据库。

3、并行数据库。

4、数据仓库与数据挖掘。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9680183.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-30
下一篇 2023-04-30

发表评论

登录后才能评论

评论列表(0条)

保存