新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
實例解析Perl語言中BEGIN和END用法
本文和大家重點學(xué)習(xí)一下Perl語言中BEGIN和END用法,Perl語言提供了兩個關(guān)鍵字:BEGIN,END。它們可以分別包含一組腳本,用于程序體運行前或者運行后的執(zhí)行。

Perl語言中BEGIN和END用法解析
Perl語言提供了兩個關(guān)鍵字:BEGIN,END。它們可以分別包含一組腳本,用于程序體運行前或者運行后的執(zhí)行,聽起來很坳口是不是?下面看三個例子就明白了!
***個例子:最簡單,最直接的!#!/usr/bin/Perl
- BEGIN{
- print"inBEGINmodule!\n";
- }
- die"exitPerlprogram!\n";
- END{
- print"inENDmodule!\n";
- }
復(fù)制代碼執(zhí)行結(jié)果:
inBEGINmodule!
exitPerlprogram!
inENDmodule!
復(fù)制代碼是不是很好理解?!
第二個例子:主程序體放在BEGIN/END前面;#!/usr/bin/Perl
- die"exitPerlprogram!\n";
- BEGIN{
- print"inBEGINmodule!\n";
- }
- END{
- print"inENDmodule!\n";
- }
復(fù)制代碼結(jié)果:
inBEGINmodule!
exitPerlprogram!
inENDmodule!
復(fù)制代碼***一種,想必大家都能想到的:#!/usr/bin/Perl
- BEGIN{
- print"inBEGINmodule!\n";
- }
- END{
- print"inENDmodule!\n";
- }
- die"exitPerlprogram!\n";
復(fù)制代碼結(jié)果還是一樣,這里我就不貼了。
總之,Perl語言中BEGIN/END模塊和所在位置無關(guān)!
網(wǎng)頁名稱:實例解析Perl語言中BEGIN和END用法
瀏覽路徑:http://www.5511xx.com/article/codhjjp.html


咨詢
建站咨詢
