LoginSignup
0
0

More than 5 years have passed since last update.

bytesプラグマ

Posted at

bytes - 文字単位ではなくバイト単位の意味論を強制する Perl プラグマ - perldoc.jp http://perldoc.jp/docs/modules/bytes-1.03/bytes.pod

bytesプラグマをuseすると、useしたレキシカルスコープ内で、
いろいろなサブルーチンの挙動が変わるらしい。
おそらく一番使われるのが文字数のサイズを取得するlengthを、
バイトサイズを取得するためにbytes::lengthとしてつかことなんじゃないでしょうか。

use strict;
use warnings;
use utf8;
use 5.010;

say length "aaa";               # => 3
say length "あああ";            # => 3

{
    say length "aaa";           # => 3
    say length "あああ";        # => 3

    use bytes;
    say length "aaa";           # => 3
    say length "あああ";        # => 9
}

say length "aaa";               # => 3
say length "あああ";            # => 3
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0