perl中->和=>作用

-> 有两种用法,都和解引用有关。 

 

第一种用法,就是解引用。 

根据 -> 后面跟的符号的不同,解不同类型的引用, 

->[] 表示解数组引用,->{} 表示解散列引用,->() 表示解子程序引用。 

例子: 

$arr_ref = /@array; 

$arr_ref->[0] 访问数组 @array 的第一个元素。 

$hash_ref = /%hash; 

$hash_ref->{foo} 访问 %hash 的 foo 分量 

$sub_ref = /&test; 

$sub_ref->(1, 2, 3) 使用参数列表 (1,2,3) 来调用 &test 这个子程序。 

 

第二种用法,就是调用类或者对象的方法。 

格式: 

$obj->method(); 

或者 

ClassName->method(); 

例如: 

$pop3->login( $username, $password ); 

my $ftp = Net::FTP->new("some.host.name", Debug => 0); 

这两种用法略有不同, 

但是总的来说,符合以下规则: 

引用:[color=red]假设 -> 的左操作数(就是左边那个值,如 $pop3 和 Net::FTP)是 $left,右操作数(就是右边那个值,如 login 和 new)是 $right,那么 -> 的运算规则就是: 

 

if ( ref $left 有效 ){    # 也就是说 $left 是个引用,而不是个裸字

 

    $ClassName = ref $left;  # 取引用的类型,当作类名称

 

}

 

else{

 

    $ClassName = $left;       # 直接把裸字当作类名称

 

 

然后调用: 

&{$ClassName::$right}( $left, 原参数列表 ) 

也就是说把类名称和右操作数拼在一起,当作子程序名称(注),并把左操作数当作第一个参数。 

 

注:Perl 解释器要做的工作其实要比这复杂,它还要考虑到继承的问题。  

 

=>作用

当给 hash 赋值时,有时并不明显哪些元素是 keys,那些是 values。例如,在下面的赋值中,我们需要仔细的计数,“ key,value,key,value,…” ,来判断2.5 是key 还是 vlaue:

%some_hash = ( “ foo” , 35, “ bar” , 12.4 ,2.5, “ hello” , “Wilma” , 1.72e30, “ betty” , “ bye/n” );

 

如果 Perl 能提供一种方法,让我们轻易的辨别出哪一个是 key,哪一个是 value,那该有多好?Larry 也想过这个问题,因此发明了大箭头符号(=>)◆。对于 Perl 来讲,其作用和和逗号(,)类似,因此有时称作 “ 胖逗号(fat comma)” 。Perl 语法中,在需要逗号(,)的时候,都可以使用大箭头符号替换;对于 Perl来讲,它们是一样的◆。下面是给 hash 赋值的另一种方法:

 

◆是的,还有小箭头(->)。它和引用一起使用,这是高级话题。如果你准备好了,可以参见perlreftut 和perlref 的帮助手册

◆它们在技术上还是有一点不同:任何大箭头符号(=>)左侧的 bareword(由字母,数字,下划线,但不是由数字开头,前面有可选的加号或减号, 组成的序列)都暗含着由引号括起来了的。因此可以省略掉大箭头符号(=>)左侧bareword上的引号。你也可以忽略掉hash的花括号中的引号,如果里面只有作为key的bareword.

 

my %last_name = (

“fred” => “flintstone”,

“dino” => undef,

“barney”=> “rubble”;

“betty”=> “rubble”,

);

 

上面代码中,很容易辨别出哪一个是 key,哪一个是 value。注意列表中最后一个逗号。我们早期讨论过,这个逗号是没什么用的,但有时能给我们带来方便;如果我们要加入新的元素到 hash 中,我们只需知道每一行都有 key/value 对,结尾有逗号。Perl 会查看不同元素之间的逗号,以及列表结尾处的逗号(此逗号非必需的)

perl中->和=>作用  
原文见: http://blog.sina.com.cn/s/blog_5f8e03960100x0si.html
sub getStripSideRailCopUsage { my $type = shift; # 【12003365】cam-残铜率检查程序优化 按最新文件要求,所有type diff均为10 my $diff = 10; my (@usageStrip,@usageUnit,$fullCopperValue,$unitFullCopperValue); ICO::OpenStep($f,$JOB,$subStep[0]); ICO::DelLayer($f,$JOB,'side_rail_fill_cop','unit_fill_cop','unit_fill_cop+++'); ICO::CreateLay($f, $JOB, "misc", "document", 'side_rail_fill_cop','unit_fill_cop','unit_fill_cop+++'); $f->COM('sr_fill', type => 'solid', solid_type => 'surface', min_brush => '2.54', use_arcs => 'yes', cut_prims => 'no', outline_draw => 'no', outline_width => 0, outline_invert => 'no', polarity => 'positive', step_margin_x => 0, step_margin_y => 0, step_max_dist_x => 2540, step_max_dist_y => 2540, sr_margin_x => '0.3', sr_margin_y => '0.3', sr_max_dist_x => 0, sr_max_dist_y => 0, nest_sr => 'no', consider_feat => 'no', feat_margin => 0, consider_drill => 'no', drill_margin => 0, consider_rout => 'no', dest => 'layer_name', layer => 'side_rail_fill_cop', stop_at_steps => ''); $fullCopperValue = ICO::GetCopperArea($f,'side_rail_fill_cop','all',0); $f->COM('profile_to_rout', layer => 'unit_fill_cop', width => 10); ICO::ClearAll($f,$JOB); $f->COM('affected_layer', name => 'unit_fill_cop', mode => 'single', affected => 'yes'); $f->COM('sel_cut_data', det_tol => '25.4', con_tol => '25.4', rad_tol => '2.54', ignore_width => 'yes', filter_overlaps => 'no', delete_doubles => 'no', use_order => 'yes', ignore_holes => 'none', start_positive => 'yes', polarity_of_touching => 'same', contourize => 'yes', simplify => 'yes', resize_thick_lines => 'no' ); ICO::ClearLayer($f); $f->COM('affected_layer', name => 'side_rail_fill_cop', mode => 'single', affected => 'yes'); $f->COM('sel_copy_other', dest => 'layer_name',target_layer => 'unit_fill_cop', invert => 'yes',dx => 0,dy => 0,size => 0,x_anchor => '0',y_anchor => '0'); ICO::ClearLayer($f); $f->COM('affected_layer', name => 'unit_fill_cop', mode => 'single', affected => 'yes'); $f->COM('sel_cont_resize', accuracy => 25.4, break_to_islands => 'yes', island_size => 0, hole_size => 0, drill_filter => 'no', corner_ctl => 'no'); ICO::ClearLayer($f); $unitFullCopperValue = ICO::GetCopperArea($f,'unit_fill_cop','all', 0); $f->COM('reset_filter_criteria', filter_name => '', criteria => 'all'); $f->COM('adv_filter_reset'); foreach my $sig (@sigLayers) { ICO::ClearAll($f,$JOB); my $tmp = ICO::GetExposeArea($f,$sig,'side_rail_fill_cop','all',0); push @usageStrip, sprintf '%.3f', $tmp/$fullCopperValue*100; $tmp = ICO::GetExposeArea($f,$sig,'unit_fill_cop','all',0); push @usageUnit, sprintf '%.3f', $tmp/$unitFullCopperValue*100; } ICO::DelLayer($f,$JOB,'side_rail_fill_cop','unit_fill_cop','unit_fill_cop+++'); ICO::ClearAll($f,$JOB); my $str = ''; my $str2 = ''; my @side = (1..99); my $layCount = @sigLayers; for (my $u = 0; $u < $layCount; $u++) { $hashCopInfo{$u}{side} = 'L'.$side[$u]; $hashCopInfo{$u}{ucop} = $usageUnit[$u]; $hashCopInfo{$u}{scop} = $usageStrip[$u]; $hashCopInfo{$u}{diff} = abs($usageStrip[$u]-$usageUnit[$u]); $hashCopInfo{$u}{status} = 'PASS'; if ($type == 1){ # RF+MSAP+压平 if ($usageUnit[$u]-$usageStrip[$u] > 0){ $diff = 4; # u>strip时,差值需要<=4%, }elsif ($usageUnit[$u]-$usageStrip[$u] <= 0){ $diff = 9; # u<strip时,差值需要<=9% } } elsif ($type == 4){ # PMIC+Tenting if ($cuThick[$u] <= 30){ $diff = 20; } elsif ($cuThick[$u] <= 40){ $diff = 15; }else { $diff = 10; } } if (abs($usageStrip[$u]-$usageUnit[$u]) > $diff) { $str .= 'L'.$side[$u].'、 stripunit残铜相差超'.$diff.'%, strip='. $usageStrip[$u] .'%, unit= '.$usageUnit[$u] ."%\n"; $hashCopInfo{$u}{status} = 'NG'; } $str2 .= 'L'.$side[$u].'、 strip='. $usageStrip[$u] .'%, unit= '.$usageUnit[$u] ."%\n"; } $hashCopInfo{count} = $layCount; if ($str ne '') { LogResult($str); } $hashCopInfo{striptopcop} = ICO::GetCopperArea($f,$sigLayers[0],'all', 1); $hashCopInfo{stripbotcop} = ICO::GetCopperArea($f,$sigLayers[-1],'all', 1); $hashCopInfo{striptopsm} = 100-ICO::GetCopperArea($f,$topSM[0],'all', 1); $hashCopInfo{stripbotsm} = 100-ICO::GetCopperArea($f,$botSM[0],'all', 1); uiShowResTable(); } sub uiShowResTable { my ($err1,$err2); my $mw3 = $mw->Toplevel(-title => "结果查看"); $mw3->geometry( '+400+300' ); $mw3->maxsize( 1000, 1200 ); my $part2 = $mw3->Frame(-borderwidth => 2, -relief => 'groove')->pack(-side=>"top",-fill=>"x"); my $frameMainB = $part2->Scrolled('Frame', -scrollbars => 'e', -borderwidth => 2, -relief => 'groove', -height => 600) ->pack(-expand => 'yes', -fill => 'both'); my $frameB = $frameMainB->Frame()->pack(-side=>"top",-expand=>"yes",-fill=>"both",-anchor=>"n",-padx=>5,-pady=>10); my $frameUnitCop = $frameB->LabFrame(-label=>"unit区域strip外围残铜数据(%)",-font=>"normal 12")->pack(-side=>"top",-fill=>"x"); my $frameUCTop = $frameUnitCop->Frame(-borderwidth => 2, -relief => 'groove')->pack(-side=>"top",-fill=>"x"); $frameUCTop->Label( -text=>"STEP",-font=>"normal 12", -width=>18, -fg=>'blue') ->pack(-side=>"left",-padx=>5,-pady=>2); for (my $i = 1; $i <= $hashCopInfo{count}; $i++) { $frameUCTop->Label( -text=>"L".$i,-font=>"normal 12", -width=>10, -fg=>'blue') ->pack(-side=>"left",-padx=>5,-pady=>2); } my $frameUCRow = $frameUnitCop->Frame(-borderwidth => 2, -relief => 'groove')->pack(-side=>"top",-fill=>"x"); $frameUCRow->Label( -text=>"unit",-font=>"normal 12", -width=>18, -fg=>'blue') ->pack(-side=>"left",-padx=>5,-pady=>2); for (my $i = 0; $i < $hashCopInfo{count}; $i++) { $frameUCRow ->Entry(-textvariable=>\$hashCopInfo{$i}{ucop}, -width=>10, -font=>"normal 12", -background=>"white") ->pack(-side=>"left",-padx=>5,-pady=>2); } my $frameUCRow2 = $frameUnitCop->Frame(-borderwidth => 2, -relief => 'groove')->pack(-side=>"top",-fill=>"x"); $frameUCRow2->Label( -text=>"strip",-font=>"normal 12", -width=>18, -fg=>'blue') ->pack(-side=>"left",-padx=>5,-pady=>2); for (my $i = 0; $i < $hashCopInfo{count}; $i++) { $frameUCRow2 ->Entry(-textvariable=>\$hashCopInfo{$i}{scop}, -width=>10, -font=>"normal 12", -background=>"white") ->pack(-side=>"left",-padx=>5,-pady=>2); } my $frameUCRow3 = $frameUnitCop->Frame(-borderwidth => 2, -relief => 'groove')->pack(-side=>"top",-fill=>"x"); $frameUCRow3->Label( -text=>"差异",-font=>"normal 12", -width=>18, -fg=>'blue') ->pack(-side=>"left",-padx=>5,-pady=>2); for (my $i = 0; $i < $hashCopInfo{count}; $i++) { $frameUCRow3 ->Entry(-textvariable=>\$hashCopInfo{$i}{diff}, -width=>10, -font=>"normal 12", -background=>"white") ->pack(-side=>"left",-padx=>5,-pady=>2); } my $frameUCRow4 = $frameUnitCop->Frame(-borderwidth => 2, -relief => 'groove')->pack(-side=>"top",-fill=>"x"); $frameUCRow4->Label( -text=>"状态",-font=>"normal 12", -width=>18, -fg=>'blue') ->pack(-side=>"left",-padx=>5,-pady=>2); for (my $i = 0; $i < $hashCopInfo{count}; $i++) { my $color = 'red'; if ($hashCopInfo{$i}{status} eq 'PASS') { $color = 'green'; } else { $err1 = 'unitstrip残铜相差超过10%(G2产品u>strip时,差值需要<=4%,u<strip时,差值需要<=9%)'; } $frameUCRow4 ->Entry(-textvariable=>\$hashCopInfo{$i}{status}, -width=>10, -font=>"normal 12", -background=>"$color") ->pack(-side=>"left",-padx=>5,-pady=>2); } if ($err1) { $needCtype = 1; $frameUnitCop->Label( -text=>"$err1",-font=>"normal 12", -width=>100, -fg=>'blue') ->pack(-side=>"top",-padx=>5,-pady=>2); } # $ed_dummy_rule ="需增加回蚀dummy流程,审单铺铜需满足以下规则:当U小于80%:S(板边)大于等于U+14%\n当U大于等于80%:S(板边)大于等于U+9%\n并提难点确认板边设计(板边残铜过高接近实铜)"; if ($ed_dummy_rule) { $frameUnitCop->Label( -text=>"$ed_dummy_rule ",-font=>"normal 12", -width=>100, -fg=>'blue') ->pack(-side=>"top",-padx=>5,-pady=>2); } my $frameFullCop = $frameB->LabFrame(-label=>"strip整板数据(%)",-font=>"normal 12")->pack(-side=>"top",-fill=>"x"); my $frameSData = $frameFullCop->Frame(-borderwidth => 2, -relief => 'groove')->pack(-side=>"top",-fill=>"x"); $frameSData->Label( -text=>"类型",-font=>"normal 12", -width=>18, -fg=>'blue') ->pack(-side=>"left",-padx=>5,-pady=>2); $frameSData->Label( -text=>"TOP",-font=>"normal 12", -width=>12, -fg=>'blue') ->pack(-side=>"left",-padx=>5,-pady=>2); $frameSData->Label( -text=>"BOTTOM",-font=>"normal 12", -width=>12, -fg=>'blue') ->pack(-side=>"left",-padx=>5,-pady=>2); $frameSData->Label( -text=>"差值",-font=>"normal 12", -width=>12, -fg=>'blue') ->pack(-side=>"left",-padx=>5,-pady=>2); $frameSData->Label( -text=>"状态",-font=>"normal 12", -width=>12, -fg=>'blue') ->pack(-side=>"left",-padx=>5,-pady=>2); my $frameSCop = $frameFullCop->Frame(-borderwidth => 2, -relief => 'groove')->pack(-side=>"top",-fill=>"x"); $frameSCop->Label( -text=>"strip残铜",-font=>"normal 12", -width=>18, -fg=>'blue') ->pack(-side=>"left",-padx=>5,-pady=>2); $frameSCop ->Entry(-textvariable=>\$hashCopInfo{striptopcop}, -width=>12, -font=>"normal 12", -background=>"white") ->pack(-side=>"left",-padx=>5,-pady=>2); $frameSCop ->Entry(-textvariable=>\$hashCopInfo{stripbotcop}, -width=>12, -font=>"normal 12", -background=>"white") ->pack(-side=>"left",-padx=>5,-pady=>2); my $cccc = sprintf('%.3f',abs($hashCopInfo{striptopcop}-$hashCopInfo{stripbotcop})); $frameSCop->Label( -text=>$cccc,-font=>"normal 12", -width=>12, -fg=>'blue') ->pack(-side=>"left",-padx=>5,-pady=>2); if (abs($hashCopInfo{striptopcop}-$hashCopInfo{stripbotcop}) > 3) { $frameSCop->Label( -text=>"NG",-font=>"normal 12", -width=>12, -fg=>'red') ->pack(-side=>"left",-padx=>5,-pady=>2); $err2 = 'strip正背面差异超3%'; } else { $frameSCop->Label( -text=>"PASS",-font=>"normal 12", -width=>12, -fg=>'green') ->pack(-side=>"left",-padx=>5,-pady=>2); } my $frameSSM = $frameFullCop->Frame(-borderwidth => 2, -relief => 'groove')->pack(-side=>"top",-fill=>"x"); $frameSSM->Label( -text=>"strip残墨",-font=>"normal 12", -width=>18, -fg=>'blue') ->pack(-side=>"left",-padx=>5,-pady=>2); $frameSSM ->Entry(-textvariable=>\$hashCopInfo{striptopsm}, -width=>12, -font=>"normal 12", -background=>"white") ->pack(-side=>"left",-padx=>5,-pady=>2); $frameSSM ->Entry(-textvariable=>\$hashCopInfo{stripbotsm}, -width=>12, -font=>"normal 12", -background=>"white") ->pack(-side=>"left",-padx=>5,-pady=>2); $frameSSM->Label( -text=>abs($hashCopInfo{striptopsm}-$hashCopInfo{stripbotsm}),-font=>"normal 12", -width=>12, -fg=>'blue') ->pack(-side=>"left",-padx=>5,-pady=>2); if (abs($hashCopInfo{striptopsm}-$hashCopInfo{stripbotsm}) > 3) { $frameSSM->Label( -text=>"NG X",-font=>"normal 12", -width=>12, -fg=>'red') ->pack(-side=>"left",-padx=>5,-pady=>2); $err2 = 'strip正背面差异超3%'; } else { $frameSSM->Label( -text=>"PASS",-font=>"normal 12", -width=>12, -fg=>'green') ->pack(-side=>"left",-padx=>5,-pady=>2); } if ($err2) { $frameFullCop->Label( -text=>"$err2",-font=>"normal 12", -width=>50, -fg=>'blue') ->pack(-side=>"top",-padx=>5,-pady=>2); $needCtype = 1; } my $frameRun = $frameB->Frame(-borderwidth => 2, -relief => 'groove')->pack(-side=>"top",-fill=>"x"); $frameRun->Button(-text=>"继续跑翘曲程序", -command=> sub{callControlWarpage();}, -width=>39,-font=>"normal 18") ->pack(-side=>"left",-padx=>2,-pady=>2); $f->COM('get_user_group'); if ($f->{COMANS} eq 'MKT') { $frameRun->Button(-text=>"直接退出", -command=> sub{exit;}, -width=>39,-font=>"normal 18") ->pack(-side=>"left",-padx=>2,-pady=>2); } } 在这段代码基础上修改、添加。并且最终要在tk界面新增zkcoupon与unit差值的对比,仿照 “unit区域strip外围残铜数据”部分的界面排布,按zkcoupon的数量增加对比栏位。如果有zkcoupon的step才执行新增操作,否则按原程序进行,也不必增加tk界面。
最新发布
12-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值