In Perl, how do I combine these 2 statements in one line?
$str=~ s/=>/:/g;
$str=~ s/\$VAR1 = {//g;
$str =~ s/(=>|\$VAR = {)/$1 eq '=>' && ':'/ge;
但是,实际上,最好不要按原样保留代码,除非您有一些确实,令人信服的理由来组合这些语句。
It's pretty simply — just change the " ;
" to " ,
" — but why? Combining two statements is not a goal, it's a means. If you told us what your goal, you could give you a better answer.
$str=~ s/=>/:/g, $str=~ s/\$VAR1 = {//g;
Other ways:
do { $str=~ s/=>/:/g; $str=~ s/\$VAR1 = {//g; };
s/=>/:/g, s/\$VAR1 = {//g for $str;
$str = $str =~ s/=>/:/gr =~ s/\$VAR1 = {//gr; # 5.14+ required.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.