ЭЛЕКТРОННАЯ БИБЛИОТЕКА КОАПП |
Сборники Художественной, Технической, Справочной, Английской, Нормативной, Исторической, и др. литературы. |
3.2.14 chopchop This function chops off the last character of a string and returns the
character chopped. The chop operator is used primarily to
remove the newline from the end of an input record, but is more
efficient than while (<PASSWD>) { chop; # avoid \n on last field @array = split /:/; ... } If you chop a @lines = `cat myfile`; chop @lines; You can actually chop anything that is an lvalue, including an assignment: chop($cwd = `pwd`); chop($answer = <STDIN>); Note that this is different from: $answer = chop($tmp = <STDIN>); # WRONG which puts a newline into $answer = substr <STDIN>, 0, -1; But this is more commonly written as: chop($answer = <STDIN>); To chop more than one character, use
substr
as an lvalue, assigning a null string.
The following removes the last
five characters of
substr($caravan, -5) = ""; The negative subscript causes substr to count from the end of the string instead of the beginning. |