Mercurial > hg > Members > anatofuz > anatofuz-tools
annotate perl-wc @ 0:78df974566a7
initial commit
author | Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 12 Nov 2018 19:56:42 +0900 |
parents | |
children |
rev | line source |
---|---|
0
78df974566a7
initial commit
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
78df974566a7
initial commit
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 use strict; |
78df974566a7
initial commit
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 use warnings; |
78df974566a7
initial commit
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 use Encode; |
78df974566a7
initial commit
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 |
78df974566a7
initial commit
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 my $buffer = do { local $/; <>; }; |
78df974566a7
initial commit
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 |
78df974566a7
initial commit
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 my $strings = decode_utf8($buffer); |
78df974566a7
initial commit
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 |
78df974566a7
initial commit
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 my $lines = $strings =~ s/\n/\n/g || 1; |
78df974566a7
initial commit
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 my $chars = length($strings); |
78df974566a7
initial commit
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 my $bytes = length($buffer); |
78df974566a7
initial commit
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 |
78df974566a7
initial commit
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 print "lines: $lines\n"; |
78df974566a7
initial commit
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 print "chars: $chars\n"; |
78df974566a7
initial commit
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 print "bytes: $bytes\n"; |