#!/usr/bin/env perl print "\nReceived signal at ",scalar localtime,"\n"; sub test1 { $_ = 'http://www.perl.com/index.html'; if (m#([^:]+)://(.*)#){ print "\$1,\$2 = $1,$2 \n"; if ($2 =~ m#([^/]+)/(.*)#){ print "\$1,$2 \n"; if ($2 =~ m#([^/]+)(.*)#){ print "\$1,$2 \n"; } } print "\$1,$2 \n"; } } &test1;
[root@master ~/perl]# ./trap.pl
Received signal at Sun Dec 15 17:32:31 2013
$1,$2 = http,www.perl.com/index.html
$1,$2 = www.perl.com,index.html
$1,$2 = index.html,
$1,index.html #退出内层作用域后,又恢复了原来的值
原文链接:https://www.f2er.com/regex/362260.html