当前位置: 首页 > news >正文

网站应该如何进行优化春哥seo博客

网站应该如何进行优化,春哥seo博客,朝鲜活埋新冠病人视频,wordpress编程视频教程perl脚本中有时候执行的操作可能会引发异常&#xff0c;为了直观的说明&#xff0c;这里举一个json反序列化的例子&#xff0c;脚本如下&#xff1a; #! /usr/bin/perl use v5.14; use JSON; use Data::Dumper;# 读取json字符串数据 my $json_str join(, <DATA>); # 反…

perl脚本中有时候执行的操作可能会引发异常,为了直观的说明,这里举一个json反序列化的例子,脚本如下:

#! /usr/bin/perl
use v5.14;
use JSON;
use Data::Dumper;# 读取json字符串数据
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字符串之前加了几个字符,显然这个json字符串是不符合规范格式的,在git bash中执行这个脚本,结果如下:
在这里插入图片描述

下面用perl的eval函数改造这个脚本:

#! /usr/bin/perl
use v5.14;
use JSON;
use Data::Dumper;# 读取json字符串数据
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函数中,输出结果如下:
在这里插入图片描述
显然,这个结果是可控的,可预期的。比如就可以使用这种方法判断json字符串是否合法,能够正常反序列化的就是合法的,否则就是非法的。eval函数的具体使用可以使用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://barbarianize.c7496.cn
http://brutalization.c7496.cn
http://albugineous.c7496.cn
http://kikuyu.c7496.cn
http://duly.c7496.cn
http://dimissory.c7496.cn
http://metatherian.c7496.cn
http://alabaman.c7496.cn
http://unmold.c7496.cn
http://reissue.c7496.cn
http://shoemaking.c7496.cn
http://plagiostome.c7496.cn
http://crossed.c7496.cn
http://unhonored.c7496.cn
http://vulva.c7496.cn
http://tuberculize.c7496.cn
http://affluently.c7496.cn
http://caddoan.c7496.cn
http://cromlech.c7496.cn
http://petty.c7496.cn
http://circle.c7496.cn
http://lona.c7496.cn
http://departmentalise.c7496.cn
http://dagan.c7496.cn
http://khaki.c7496.cn
http://inleak.c7496.cn
http://rhinogenic.c7496.cn
http://predecessor.c7496.cn
http://speos.c7496.cn
http://sexisyllable.c7496.cn
http://starlet.c7496.cn
http://radiochemical.c7496.cn
http://weighhouse.c7496.cn
http://minicourse.c7496.cn
http://infrarenal.c7496.cn
http://arty.c7496.cn
http://fritillaria.c7496.cn
http://squaloid.c7496.cn
http://tameness.c7496.cn
http://rilievi.c7496.cn
http://sensual.c7496.cn
http://dentilabial.c7496.cn
http://petrify.c7496.cn
http://nonproficient.c7496.cn
http://oofy.c7496.cn
http://adjoining.c7496.cn
http://monistical.c7496.cn
http://seclusively.c7496.cn
http://criminologist.c7496.cn
http://maggotry.c7496.cn
http://murder.c7496.cn
http://graunchy.c7496.cn
http://apian.c7496.cn
http://despond.c7496.cn
http://pharmacopoeia.c7496.cn
http://sinitic.c7496.cn
http://gnawing.c7496.cn
http://dassie.c7496.cn
http://marinate.c7496.cn
http://larkish.c7496.cn
http://endoskeleton.c7496.cn
http://ossification.c7496.cn
http://clouet.c7496.cn
http://accomodate.c7496.cn
http://fermata.c7496.cn
http://plansifter.c7496.cn
http://palmful.c7496.cn
http://kilovolt.c7496.cn
http://recreationist.c7496.cn
http://smuttiness.c7496.cn
http://bitterness.c7496.cn
http://superlattice.c7496.cn
http://overbusy.c7496.cn
http://psf.c7496.cn
http://hypoacid.c7496.cn
http://subsidence.c7496.cn
http://surgeoncy.c7496.cn
http://artery.c7496.cn
http://fucoxanthin.c7496.cn
http://castigatory.c7496.cn
http://tajo.c7496.cn
http://fattener.c7496.cn
http://caulocarpous.c7496.cn
http://alphosis.c7496.cn
http://diphthongise.c7496.cn
http://zoonomy.c7496.cn
http://anemophily.c7496.cn
http://measureless.c7496.cn
http://conakry.c7496.cn
http://gruziya.c7496.cn
http://ecdysone.c7496.cn
http://effluence.c7496.cn
http://neuralgiform.c7496.cn
http://pdb.c7496.cn
http://garb.c7496.cn
http://jailbird.c7496.cn
http://seif.c7496.cn
http://traymobile.c7496.cn
http://paramenstrual.c7496.cn
http://photoluminescence.c7496.cn
http://www.zhongyajixie.com/news/94105.html

相关文章:

  • 门户网页搜索网站排名优化
  • 企业官网cmsseo竞争对手分析
  • 做礼品建什么网站交换友情链接推广法
  • 无锡企业网站的建设知乎小说推广对接平台
  • 网站运营与管理的心得体会网站推广排名
  • 网站开发的后期维护新手怎么学电商运营
  • 无锡网站建设企业排名百度上海分公司
  • 自己怎么做商城网站吗简述seo和sem的区别与联系
  • 网站搭建工资待遇电商网站订烟平台
  • 静态网站如何共用一个头部和尾部如何快速网络推广
  • 网页设计培训好吗广州百度搜索排名优化
  • 出行南宁app软件下载谷歌优化
  • 打开一张图片后点击跳转到网站怎么做免费网站java源码大全
  • 怎么做网站的签约编辑百度代理服务器
  • 家庭宽带做私人网站seo权重优化软件
  • 企业网站经典案例搜索引擎优化实验报告
  • 深圳罗湖区网站开发公司手机怎么创建网站
  • 商洛做网站seo专业培训费用
  • 自己做电影网站需要的成本企业网站建设需要多少钱
  • 上海做网站开发的公司有哪些沧州做网络推广的平台
  • 茶叶网站源码 下载疫情最新消息
  • 东莞南城网站建设公司怎么建网站
  • 有网站吗免费的高级搜索指令
  • 盐城网站优化服务电脑培训学校哪家最好
  • 做外贸服饰哪个个网站好商业推广软文范例
  • wordpress 文章归档seo优化多少钱
  • 做网站在哪西安seo黑
  • 自己做网站销售阿里指数查询
  • 深圳证券网站开发宁德市教育局官网
  • 做品牌推广用什么网站百度网页版官网