It's a precedence issue, the && is binding stronger than you think. Use extra parens, or use and, which has lower precedence. See perlop for the precedence table. Here's an explanation-by-code:
$ perl -MO=Deparse,-p -e 'substr ( $_,2,8 ) = " " && substr ( $ +_,15,5 ) = " " if /^AB/' (/^AB/ and substr($_, 2, 8) = (substr($_, 15, 5) = ' ')); $ perl -MO=Deparse,-p -e 'substr ( $_,2,8 ) = " " and substr ( +$_,15,5 ) = " " if /^AB/' (/^AB/ and ((substr($_, 2, 8) = ' ') and substr($_, 15, 5) = ' + ')); $ echo "AB2014052012345HELLOWORLD" | perl -pe 'substr ( $_,2,8 ) = " + " && substr ( $_,15,5 ) = " " if /^AB/' AB 12345 WORLD $ echo "AB2014052012345HELLOWORLD" | perl -pe 'substr ( $_,2,8 ) = " + " and substr ( $_,15,5 ) = " " if /^AB/' AB 12345 WORLD
In reply to Re: Multiple substr in Perl one-liner
by Anonymous Monk
in thread Multiple substr in Perl one-liner
by dirtdog
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |