#!/usr/bin/perl # # Count the number of characters in a file # File must be encoded in UTF-8. # End-of-line can be either LF or CR-LF use strict; use warnings; use open IN => ":encoding(UTF-8)"; $/ = undef; foreach my $f (@ARGV) { operate($f); } exit; sub operate { my ($f) = @_; open(F, $f) or warn("Failed to open $f: $!\n"); $_ = <F>; s/(\r)?\n//g; print sprintf("%d %s\n", length($_), $f); }
文字数を数えるプログラム chrcount
コメントをどうぞ