開発環境
- OS X Mavericks - Apple(OS)
- BBEdit - Bare Bones Software, Inc., Emacs (Text Editor)
- Perl (プログラミング言語)
初めてのPerl 第6版 (Randal L. Schwartz (著)、brian d foy (著)、Tom Phoenix (著)、近藤 嘉雪 (翻訳)、オライリージャパン)、14章(文字列処理とソート)の14.5(練習問題)3.を解いてみる。
その他参考書籍
14.5(練習問題)3.
コード(BBEdit, Emacs)
sample305_3.pl
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use 5.016;
binmode STDIN, ':utf8';
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
print '文字列を入力: ';
chomp(my $str = <STDIN>);
print '部分文字列を入力: ';
chomp(my $sub_str = <STDIN>);
my $i = index($str, $sub_str);
while ($i >= 0) {
print "$i ";
$i = index($str, $sub_str, $i + 1);
}
print "\n";
入出力結果(Terminal)
$ ./sample305_3.pl 文字列を入力: This is a test. 部分文字列を入力: is 2 5 $ ./sample305_3.pl 文字列を入力: This is a test. 部分文字列を入力: a 8 $ ./sample305_3.pl # 10 13 文字列を入力: This is a test. 部分文字列を入力: t 10 13 $ y rubble $
0 コメント:
コメントを投稿