作者gecer (gecer)
看板Perl
标题[问题] Perl do 用法
时间Wed Feb 28 18:43:51 2018
my $line = "Just another regex hacker, Perl hacker, and that's it!\n";
while( 1 )
{
my( $found, $type )= do {
if( $line =~ /\G([a-z]+(?:'[ts])?)/igc )
{ ( $1, "a word" ) }
elsif( $line =~ /\G (\n) /xgc )
{ ( $1, "newline char" ) }
elsif( $line =~ /\G (\s+) /xgc )
{ ( $1, "whitespace" ) }
elsif( $line =~ /\G ( [[:punct:]] ) /xgc )
{ ( $1, "punctuation char" ) }
else
{ last; () }
};
print "Found a $type [$found]\n";
}
小弟参考code 如上 请问这里的do {...}的用意? 非 do {..} while
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 111.255.6.125
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Perl/M.1519814633.A.6D8.html