How do I get the length of a string in Perl?

后端 未结 6 1681
清歌不尽
清歌不尽 2020-12-29 18:14

What is the Perl equivalent of strlen()?

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 18:45

    perldoc -f length
    
       length EXPR
       length  Returns the length in characters of the value of EXPR.  If EXPR is
               omitted, returns length of $_.  Note that this cannot be used on an
               entire array or hash to find out how many elements these have.  For
               that, use "scalar @array" and "scalar keys %hash" respectively.
    
               Note the characters: if the EXPR is in Unicode, you will get the num-
               ber of characters, not the number of bytes.  To get the length in
               bytes, use "do { use bytes; length(EXPR) }", see bytes.
    

提交回复
热议问题