2019-03-31 11:00:21 +00:00
|
|
|
|
---
|
|
|
|
|
title: ちょっとミスしてた
|
|
|
|
|
author: kazu634
|
|
|
|
|
date: 2007-12-06
|
|
|
|
|
wordtwit_post_info:
|
|
|
|
|
- 'O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:3411;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}'
|
|
|
|
|
categories:
|
|
|
|
|
- Perl
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
<div class="section">
|
|
|
|
|
<p>
|
|
|
|
|
最後の13桁目はチェックデジットだから、無視しなきゃいけなかった。だからこんな感じ:
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<pre class="syntax-highlight">
|
|
|
|
|
<span class="synStatement">use strict</span>;
|
|
|
|
|
<span class="synStatement">use warnings</span>;
|
|
|
|
|
<span class="synComment"># 変数の宣言</span>
|
|
|
|
|
<span class="synStatement">my</span> <span class="synIdentifier">$temp_isbn</span>;
|
|
|
|
|
<span class="synStatement">my</span> <span class="synIdentifier">$_odd</span>;
|
|
|
|
|
<span class="synStatement">my</span> <span class="synIdentifier">$_even</span>;
|
|
|
|
|
<span class="synComment"># 適当なisbn10を代入して、978をつける</span>
|
|
|
|
|
<span class="synIdentifier">$temp_isbn</span> = <span class="synConstant">'978'</span> . <span class="synConstant">'4582744176'</span>;
|
|
|
|
|
<span class="synStatement">print</span> <span class="synConstant">"isbn: "</span> . <span class="synIdentifier">$temp_isbn</span> . <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|
|
|
|
<span class="synComment"># 一桁ずつばらして配列@fooに代入</span>
|
|
|
|
|
<span class="synStatement">my</span> <span class="synIdentifier">@foo</span> = <span class="synStatement">split</span>(<span class="synStatement">//</span>, <span class="synIdentifier">$temp_isbn</span>);
|
|
|
|
|
<span class="synComment"># 奇数の処理</span>
|
|
|
|
|
<span class="synComment"># @fooには13桁のisbnが入っている。配列は0-12まで。</span>
|
|
|
|
|
<span class="synComment"># @foo[12]はチェックデジットなので、しかとする。</span>
|
|
|
|
|
<span class="synStatement">print</span> <span class="synConstant">'Odd Number: '</span>;
|
|
|
|
|
<span class="synStatement">for</span> (<span class="synStatement">my</span> <span class="synIdentifier">$i</span> = <span class="synConstant"></span>; <span class="synIdentifier">$i</span> <= <span class="synConstant">11</span>; <span class="synIdentifier">$i</span> = <span class="synIdentifier">$i</span> + <span class="synConstant">2</span>){
|
|
|
|
|
<span class="synIdentifier">$_odd</span> += <span class="synIdentifier">$foo</span>[<span class="synIdentifier">$i</span>];
|
|
|
|
|
<span class="synStatement">print</span> <span class="synIdentifier">$foo</span>[<span class="synIdentifier">$i</span>] . <span class="synConstant">" "</span>;
|
|
|
|
|
}
|
|
|
|
|
<span class="synStatement">print</span> <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|
|
|
|
<span class="synComment"># 偶数の処理。以下同文。</span>
|
|
|
|
|
<span class="synStatement">print</span> <span class="synConstant">'Even Number: '</span>;
|
|
|
|
|
<span class="synStatement">for</span> (<span class="synStatement">my</span> <span class="synIdentifier">$i</span> = <span class="synConstant">1</span>; <span class="synIdentifier">$i</span> <= <span class="synConstant">11</span>; <span class="synIdentifier">$i</span> = <span class="synIdentifier">$i</span> + <span class="synConstant">2</span>){
|
|
|
|
|
<span class="synIdentifier">$_even</span> += <span class="synIdentifier">$foo</span>[<span class="synIdentifier">$i</span>];
|
|
|
|
|
<span class="synStatement">print</span> <span class="synIdentifier">$foo</span>[<span class="synIdentifier">$i</span>] . <span class="synConstant">" "</span>;
|
|
|
|
|
}
|
|
|
|
|
<span class="synStatement">print</span> <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
|
<li>
|
|
|
|
|
元記事 <ul>
|
|
|
|
|
<li>
|
|
|
|
|
<a href="http://d.hatena.ne.jp/sirocco634/20071203#1196608244" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/sirocco634/20071203#1196608244', '2007-12-03 – 武蔵の日記');" target="_blank">2007-12-03 – 武蔵の日記</a>
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<a href="http://d.hatena.ne.jp/sirocco634/20071202#1196605129" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/sirocco634/20071202#1196605129', '2007-12-02 – 武蔵の日記');" target="_blank">2007-12-02 – 武蔵の日記</a>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
2019-04-02 16:06:15 +00:00
|
|
|
|
</div>
|