開発環境
- OS X Mavericks - Apple(OS)
- BBEdit - Bare Bones Software, Inc., Emacs (Text Editor)
- Perl (プログラミング言語)
初めてのPerl 第6版 (Randal L. Schwartz (著)、brian d foy (著)、Tom Phoenix (著)、近藤 嘉雪 (翻訳)、オライリージャパン)、6章(ハッシュ)の6.6(練習問題)2.を解いてみる。
その他参考書籍
6.6(練習問題)2.
コード(BBEdit, Emacs)
sample.pl
#!/usr/bin/env perl
# use diagnostics;
use strict;
use warnings;
use 5.016;
use utf8;
binmode STDIN, ':utf8';
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
my %words_count;
my $file_name = $ARGV[0];
open my $in_fh, '<', $file_name or die "can't open $file_name: $!";
while (<$in_fh>) {
chomp;
$words_count{$_} += 1;
}
close $in_fh or die "can't close $file_name: $!";
for (sort keys %words_count) {
say "$_: $words_count{$_}";
}
入出力結果(Terminal)
$ ./sample.pl sample148.txt barney: 1 dino: 1 fred: 3 wilma: 1 $ cat sample148.txt fred barney fred dino wilma fred $
0 コメント:
コメントを投稿