substr rindex . rindex , , substr :
This substr works on $_, starts at the position given rindex, replaces the following character 1 \nLAST=:
while( <> ) {
substr( $_, rindex( $_, ' ' ), 1, "\nLAST=" ) if /\AGIVEN=/;
print;
}
When you look at this code, you see that you already need it in the form for a single-line interface, although in this case I use generalized quoting to avoid problems with shell interpolation:
% perl -pi.old -e 'substr($_,rindex($_,q( )),1,qq(\nLAST=)) if /\AGIVEN=/' ...
This, however, can lead to the distortion of the names of some people. Not every surname is one word. Asking for a person is the only good way to find out what their last name is.
source
share