自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

實(shí)例解析Perl語言中BEGIN和END用法

開發(fā) 架構(gòu)
Perl語言提供了兩個(gè)關(guān)鍵字:BEGIN,END。它們可以分別包含一組腳本,用于程序體運(yùn)行前或者運(yùn)行后的執(zhí)行,本文通過實(shí)例向大家做一下介紹。

本文和大家重點(diǎn)學(xué)習(xí)一下Perl語言中BEGIN和END用法,Perl語言提供了兩個(gè)關(guān)鍵字:BEGIN,END。它們可以分別包含一組腳本,用于程序體運(yùn)行前或者運(yùn)行后的執(zhí)行。

Perl語言中BEGIN和END用法解析

Perl語言提供了兩個(gè)關(guān)鍵字:BEGIN,END。它們可以分別包含一組腳本,用于程序體運(yùn)行前或者運(yùn)行后的執(zhí)行,聽起來很坳口是不是?下面看三個(gè)例子就明白了!

***個(gè)例子:最簡(jiǎn)單,最直接的!#!/usr/bin/Perl

  1. BEGIN{  
  2.  
  3. print"inBEGINmodule!\n";  
  4.  
  5. }  
  6.  
  7. die"exitPerlprogram!\n";  
  8.  
  9. END{  
  10.  
  11. print"inENDmodule!\n";  
  12.  
  13. }  
  14.  

復(fù)制代碼執(zhí)行結(jié)果:

inBEGINmodule!

exitPerlprogram!

inENDmodule!
復(fù)制代碼是不是很好理解?!

第二個(gè)例子:主程序體放在BEGIN/END前面;#!/usr/bin/Perl

  1. die"exitPerlprogram!\n";  
  2.  
  3. BEGIN{  
  4.  
  5. print"inBEGINmodule!\n";  
  6.  
  7. }  
  8.  
  9. END{  
  10.  
  11. print"inENDmodule!\n";  
  12.  
  13. }  
  14.  

復(fù)制代碼結(jié)果:

inBEGINmodule!

exitPerlprogram!

inENDmodule!
復(fù)制代碼***一種,想必大家都能想到的:#!/usr/bin/Perl

  1. BEGIN{  
  2.  
  3. print"inBEGINmodule!\n";  
  4.  
  5. }  
  6.  
  7. END{  
  8.  
  9. print"inENDmodule!\n";  
  10.  
  11. }  
  12.  
  13. die"exitPerlprogram!\n";  
  14.  

復(fù)制代碼結(jié)果還是一樣,這里我就不貼了。

總之,Perl語言中BEGIN/END模塊和所在位置無關(guān)!

【編輯推薦】

  1. Eclipse平臺(tái)中Perl腳本開發(fā)
  2. Perl學(xué)習(xí)筆記----Perl命令行
  3. Perl數(shù)組和引用使用指導(dǎo)
  4. Perl基礎(chǔ) 解析Perl標(biāo)量和數(shù)組概念
  5. Perl模式匹配中的特殊字符用法指南


 

責(zé)任編輯:佚名 來源: csdn.net
相關(guān)推薦

2010-07-23 13:23:10

Perl語言

2010-07-13 15:34:09

Perl語言

2010-07-19 10:01:57

Perl函數(shù)

2010-07-16 08:47:53

Perl if語句

2010-07-20 09:45:04

Perl繼承

2010-07-20 10:02:15

Perl類

2010-07-26 16:23:23

Perl語言

2010-07-15 15:54:10

Perl守護(hù)進(jìn)程

2010-07-19 09:16:47

Perl包

2010-07-21 09:50:51

Perl調(diào)試

2010-07-20 11:37:00

Perl函數(shù)返回值

2010-07-20 15:02:20

Perl數(shù)組

2010-07-23 13:07:39

Perl

2010-07-13 13:49:43

Perl foreac

2010-07-19 15:37:48

Perl日期時(shí)間

2010-07-16 13:10:36

Perl哈希表

2010-07-14 15:32:21

Perl轉(zhuǎn)義字符

2010-07-19 14:13:41

Perl函數(shù)

2010-07-15 10:22:23

Perl控制結(jié)構(gòu)

2010-07-16 16:56:01

Perl構(gòu)造函數(shù)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)