中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

網(wǎng)站應(yīng)該如何進(jìn)行優(yōu)化網(wǎng)絡(luò)營(yíng)銷分類

網(wǎng)站應(yīng)該如何進(jìn)行優(yōu)化,網(wǎng)絡(luò)營(yíng)銷分類,如何更快的學(xué)習(xí).net網(wǎng)站開(kāi)發(fā),網(wǎng)站建設(shè)公司廠perl腳本中有時(shí)候執(zhí)行的操作可能會(huì)引發(fā)異常&#xff0c;為了直觀的說(shuō)明&#xff0c;這里舉一個(gè)json反序列化的例子&#xff0c;腳本如下&#xff1a; #! /usr/bin/perl use v5.14; use JSON; use Data::Dumper;# 讀取json字符串?dāng)?shù)據(jù) my $json_str join(, <DATA>); # 反…

perl腳本中有時(shí)候執(zhí)行的操作可能會(huì)引發(fā)異常,為了直觀的說(shuō)明,這里舉一個(gè)json反序列化的例子,腳本如下:

#! /usr/bin/perl
use v5.14;
use JSON;
use Data::Dumper;# 讀取json字符串?dāng)?shù)據(jù)
my $json_str = join('', <DATA>);
# 反序列化操作
my $json = from_json($json_str);say to_json($json, { pretty => 1 });__DATA__
bad {"id" : 1024,"desc" : "hello world","other" : {"test_null" : null,"test_false" : false,"test_true" : true}
}

在這里插入圖片描述

腳本中有意把正確json字符串之前加了幾個(gè)字符,顯然這個(gè)json字符串是不符合規(guī)范格式的,在git bash中執(zhí)行這個(gè)腳本,結(jié)果如下:
在這里插入圖片描述

下面用perl的eval函數(shù)改造這個(gè)腳本:

#! /usr/bin/perl
use v5.14;
use JSON;
use Data::Dumper;# 讀取json字符串?dāng)?shù)據(jù)
my $json_str = join('', <DATA>);
# 反序列化操作
my $json = eval {return from_json($json_str);
};unless (defined $json) {say "from_json failed !!!!";
} else {say to_json($json, { pretty => 1 });
}__DATA__
bad {"id" : 1024,"desc" : "hello world","other" : {"test_null" : null,"test_false" : false,"test_true" : true}
}

腳本中用把from_json的操作放在eval函數(shù)中,輸出結(jié)果如下:
在這里插入圖片描述
顯然,這個(gè)結(jié)果是可控的,可預(yù)期的。比如就可以使用這種方法判斷json字符串是否合法,能夠正常反序列化的就是合法的,否則就是非法的。eval函數(shù)的具體使用可以使用perldoc -f eval查看。

    eval EXPReval BLOCKeval    "eval" in all its forms is used to execute a little Perlprogram, trapping any errors encountered so they don't crash thecalling program.Plain "eval" with no argument is just "eval EXPR", where theexpression is understood to be contained in $_. Thus there areonly two real "eval" forms; the one with an EXPR is often called"string eval". In a string eval, the value of the expression(which is itself determined within scalar context) is firstparsed, and if there were no errors, executed as a block withinthe lexical context of the current Perl program. This form istypically used to delay parsing and subsequent execution of thetext of EXPR until run time. Note that the value is parsed everytime the "eval" executes.The other form is called "block eval". It is less general thanstring eval, but the code within the BLOCK is parsed only once(at the same time the code surrounding the "eval" itself wasparsed) and executed within the context of the current Perlprogram. This form is typically used to trap exceptions moreefficiently than the first, while also providing the benefit ofchecking the code within BLOCK at compile time. BLOCK is parsedand compiled just once. Since errors are trapped, it often isused to check if a given feature is available.In both forms, the value returned is the value of the lastexpression evaluated inside the mini-program; a return statementmay also be used, just as with subroutines. The expressionproviding the return value is evaluated in void, scalar, or listcontext, depending on the context of the "eval" itself. See"wantarray" for more on how the evaluation context can bedetermined.If there is a syntax error or runtime error, or a "die"statement is executed, "eval" returns "undef" in scalar context,or an empty list in list context, and $@ is set to the errormessage. (Prior to 5.16, a bug caused "undef" to be returned inlist context for syntax errors, but not for runtime errors.) Ifthere was no error, $@ is set to the empty string. A controlflow operator like "last" or "goto" can bypass the setting of$@. Beware that using "eval" neither silences Perl from printingwarnings to STDERR, nor does it stuff the text of warningmessages into $@. To do either of those, you have to use the$SIG{__WARN__} facility, or turn off warnings inside the BLOCKor EXPR using "no warnings 'all'". See "warn", perlvar, andwarnings.Note that, because "eval" traps otherwise-fatal errors, it isuseful for determining whether a particular feature (such as"socket" or "symlink") is implemented. It is also Perl'sexception-trapping mechanism, where the "die" operator is usedto raise exceptions.Before Perl 5.14, the assignment to $@ occurred beforerestoration of localized variables, which means that for yourcode to run on older versions, a temporary is required if youwant to mask some, but not all errors:# alter $@ on nefarious repugnancy only{my $e;{local $@; # protect existing $@eval { test_repugnancy() };# $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only$@ =~ /nefarious/ and $e = $@;}die $e if defined $e}There are some different considerations for each form:String evalSince the return value of EXPR is executed as a block withinthe lexical context of the current Perl program, any outerlexical variables are visible to it, and any packagevariable settings or subroutine and format definitionsremain afterwards.Under the "unicode_eval" featureIf this feature is enabled (which is the default under a"use 5.16" or higher declaration), EXPR is considered tobe in the same encoding as the surrounding program. Thusif "use utf8" is in effect, the string will be treatedas being UTF-8 encoded. Otherwise, the string isconsidered to be a sequence of independent bytes. Bytesthat correspond to ASCII-range code points will havetheir normal meanings for operators in the string. Thetreatment of the other bytes depends on if the"'unicode_strings"" feature is in effect.In a plain "eval" without an EXPR argument, being in"use utf8" or not is irrelevant; the UTF-8ness of $_itself determines the behavior.Any "use utf8" or "no utf8" declarations within thestring have no effect, and source filters are forbidden.("unicode_strings", however, can appear within thestring.) See also the "evalbytes" operator, which worksproperly with source filters.Variables defined outside the "eval" and used inside itretain their original UTF-8ness. Everything inside thestring follows the normal rules for a Perl program withthe given state of "use utf8".Outside the "unicode_eval" featureIn this case, the behavior is problematic and is not soeasily described. Here are two bugs that cannot easilybe fixed without breaking existing programs:*   It can lose track of whether something should beencoded as UTF-8 or not.*   Source filters activated within "eval" leak out intowhichever file scope is currently being compiled. Togive an example with the CPAN moduleSemi::Semicolons:BEGIN { eval "use Semi::Semicolons; # not filtered" }# filtered here!"evalbytes" fixes that to work the way one wouldexpect:use feature "evalbytes";BEGIN { evalbytes "use Semi::Semicolons; # filtered" }# not filteredProblems can arise if the string expands a scalar containinga floating point number. That scalar can expand to letters,such as "NaN" or "Infinity"; or, within the scope of a "uselocale", the decimal point character may be something otherthan a dot (such as a comma). None of these are likely toparse as you are likely expecting.You should be especially careful to remember what's beinglooked at when:eval $x;        # CASE 1eval "$x";      # CASE 2eval '$x';      # CASE 3eval { $x };    # CASE 4eval "\$$x++";  # CASE 5$$x++;          # CASE 6Cases 1 and 2 above behave identically: they run the codecontained in the variable $x. (Although case 2 hasmisleading double quotes making the reader wonder what elsemight be happening (nothing is).) Cases 3 and 4 likewisebehave in the same way: they run the code '$x', which doesnothing but return the value of $x. (Case 4 is preferred forpurely visual reasons, but it also has the advantage ofcompiling at compile-time instead of at run-time.) Case 5 isa place where normally you *would* like to use doublequotes, except that in this particular situation, you canjust use symbolic references instead, as in case 6.An "eval ''" executed within a subroutine defined in the"DB" package doesn't see the usual surrounding lexicalscope, but rather the scope of the first non-DB piece ofcode that called it. You don't normally need to worry aboutthis unless you are writing a Perl debugger.The final semicolon, if any, may be omitted from the valueof EXPR.Block evalIf the code to be executed doesn't vary, you may use theeval-BLOCK form to trap run-time errors without incurringthe penalty of recompiling each time. The error, if any, isstill returned in $@. Examples:# make divide-by-zero nonfataleval { $answer = $a / $b; }; warn $@ if $@;# same thing, but less efficienteval '$answer = $a / $b'; warn $@ if $@;# a compile-time erroreval { $answer = }; # WRONG# a run-time erroreval '$answer =';   # sets $@If you want to trap errors when loading an XS module, someproblems with the binary interface (such as Perl versionskew) may be fatal even with "eval" unless$ENV{PERL_DL_NONLAZY} is set. See perlrun.Using the "eval {}" form as an exception trap in librariesdoes have some issues. Due to the current arguably brokenstate of "__DIE__" hooks, you may wish not to trigger any"__DIE__" hooks that user code may have installed. You canuse the "local $SIG{__DIE__}" construct for this purpose, asthis example shows:# a private exception trap for divide-by-zeroeval { local $SIG{'__DIE__'}; $answer = $a / $b; };warn $@ if $@;This is especially significant, given that "__DIE__" hookscan call "die" again, which has the effect of changing theirerror messages:# __DIE__ hooks may modify error messages{local $SIG{'__DIE__'} =sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x };eval { die "foo lives here" };print $@ if $@;                # prints "bar lives here"}Because this promotes action at a distance, thiscounterintuitive behavior may be fixed in a future release."eval BLOCK" does *not* count as a loop, so the loop controlstatements "next", "last", or "redo" cannot be used to leaveor restart the block.The final semicolon, if any, may be omitted from within theBLOCK.
http://m.risenshineclean.com/news/64119.html

相關(guān)文章:

  • 做網(wǎng)站建網(wǎng)站安卓手機(jī)游戲優(yōu)化器
  • 河南企業(yè)網(wǎng)站制作個(gè)人怎么做網(wǎng)站
  • 中國(guó)域名注冊(cè)中心做博客的seo技巧
  • 上海專業(yè)制作電子商務(wù)網(wǎng)站廣西seo公司
  • 做字的網(wǎng)站個(gè)人友情鏈接推廣
  • wordpress編輯器 模板seopeixun com cn
  • 動(dòng)態(tài)網(wǎng)站開(kāi)發(fā) 實(shí)訓(xùn)總結(jié)環(huán)球貿(mào)易網(wǎng)
  • 解除網(wǎng)站被攔截的方法快手流量推廣免費(fèi)網(wǎng)站
  • 合肥建網(wǎng)站公司騰訊與中國(guó)聯(lián)通
  • 各大網(wǎng)站提交入口怎么聯(lián)系地推公司
  • 西安火車站網(wǎng)站建設(shè)安卓?jī)?yōu)化大師官方下載
  • 頂級(jí)裝修公司百度小程序優(yōu)化
  • 莆田網(wǎng)站建設(shè)技術(shù)托管南陽(yáng)網(wǎng)站seo
  • 開(kāi)發(fā)公司屬于什么行業(yè)網(wǎng)站優(yōu)化 seo和sem
  • 中國(guó)專業(yè)的網(wǎng)站建設(shè)12月10日新聞
  • 義烏多語(yǔ)言網(wǎng)站建設(shè)seo網(wǎng)絡(luò)推廣技術(shù)
  • 做五金生意什么網(wǎng)站做比較好精準(zhǔn)營(yíng)銷的三要素
  • 網(wǎng)站首頁(yè)的模塊布局杭州百度快速排名提升
  • 做競(jìng)猜網(wǎng)站合法嗎如何快速提升網(wǎng)站關(guān)鍵詞排名
  • 哪個(gè)平臺(tái)查企業(yè)免費(fèi)谷歌aso優(yōu)化
  • 專業(yè)做網(wǎng)站公司哪家好一句簡(jiǎn)短走心文案
  • 個(gè)人做理財(cái)網(wǎng)站好上海seo關(guān)鍵詞優(yōu)化
  • ppt中仿網(wǎng)站鏈接怎么做b站引流推廣網(wǎng)站
  • 做網(wǎng)站的步驟流程seo外包杭州
  • 網(wǎng)站建設(shè)全套流程廣州seo全網(wǎng)營(yíng)銷
  • 網(wǎng)站建設(shè)中的咨詢服務(wù)北京網(wǎng)絡(luò)推廣
  • 網(wǎng)站建設(shè)色系搭配種子資源
  • 長(zhǎng)沙畢業(yè)設(shè)計(jì)代做網(wǎng)站價(jià)格網(wǎng)域名查詢地址
  • 如何做微商城網(wǎng)站建設(shè)國(guó)內(nèi)推廣平臺(tái)
  • 網(wǎng)站開(kāi)發(fā)主流技術(shù)線路介紹網(wǎng)站制作論文