471 lines
26 KiB
Markdown
471 lines
26 KiB
Markdown
|
---
|
|||
|
title: はじめて実用的な目的でPerlを用いた
|
|||
|
author: kazu634
|
|||
|
date: 2007-12-26
|
|||
|
url: /2007/12/26/_764/
|
|||
|
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:3527;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}'
|
|||
|
categories:
|
|||
|
- diary
|
|||
|
- Perl
|
|||
|
|
|||
|
---
|
|||
|
<div class="section">
|
|||
|
<p>
|
|||
|
現在私は予備校の寮でパートとして働いている。そこでは、退寮日を寮生全体に尋ね、その日時と部屋番号、そして寮費の納入方式(一括or二回or月払い)に応じて一月に引き落とされる金額が決定される。そこで私は、これをPerlで計算させようと決意した。四月からはこれぐらいできないといけないだろうし。今ならいっぱい失敗することもできるしね。プログラミングの初歩をかじったことのある人による、Perl体験日記。
|
|||
|
</p>
|
|||
|
|
|||
|
<p>
|
|||
|
<a name="seemore"></a><br />
|
|||
|
</p>
|
|||
|
|
|||
|
<h4>
|
|||
|
計算方法の分析
|
|||
|
</h4>
|
|||
|
|
|||
|
<p>
|
|||
|
B棟
|
|||
|
</p>
|
|||
|
|
|||
|
<table>
|
|||
|
<tr>
|
|||
|
<th>
|
|||
|
寮費の支払い方式
|
|||
|
</th>
|
|||
|
|
|||
|
<th>
|
|||
|
1/16-1/31
|
|||
|
</th>
|
|||
|
|
|||
|
<th>
|
|||
|
2/1-2/15
|
|||
|
</th>
|
|||
|
|
|||
|
<th>
|
|||
|
2/16-2/29
|
|||
|
</th>
|
|||
|
|
|||
|
<th>
|
|||
|
3/1-3/15
|
|||
|
</th>
|
|||
|
</tr>
|
|||
|
|
|||
|
<tr>
|
|||
|
<th>
|
|||
|
一括
|
|||
|
</th>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(10,000)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(10,000)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(20,000)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(30,000)+3月分寮費(2,300×日数)
|
|||
|
</td>
|
|||
|
</tr>
|
|||
|
|
|||
|
<tr>
|
|||
|
<th>
|
|||
|
二回
|
|||
|
</th>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(10,000)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(10,000)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(20,000)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(30,000)+3月分寮費(2,300×日数)
|
|||
|
</td>
|
|||
|
</tr>
|
|||
|
|
|||
|
<tr>
|
|||
|
<th>
|
|||
|
月払い
|
|||
|
</th>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(10,000)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(10,000)+2月分寮費(66,300)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(20,000)+概算光熱費(66,300)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(30,000)+2月分寮費(66,300)+3月分寮費(2,300×日数)
|
|||
|
</td>
|
|||
|
</tr>
|
|||
|
</table>
|
|||
|
|
|||
|
<p>
|
|||
|
C棟
|
|||
|
</p>
|
|||
|
|
|||
|
<table>
|
|||
|
<tr>
|
|||
|
<th>
|
|||
|
寮費の支払い方式
|
|||
|
</th>
|
|||
|
|
|||
|
<th>
|
|||
|
1/16-1/31
|
|||
|
</th>
|
|||
|
|
|||
|
<th>
|
|||
|
2/1-2/15
|
|||
|
</th>
|
|||
|
|
|||
|
<th>
|
|||
|
2/16-2/29
|
|||
|
</th>
|
|||
|
|
|||
|
<th>
|
|||
|
3/1-3/15
|
|||
|
</th>
|
|||
|
</tr>
|
|||
|
|
|||
|
<tr>
|
|||
|
<th>
|
|||
|
一括
|
|||
|
</th>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(20,000)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(20,000)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(30,000)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(40,000)+3月分寮費(2,900×日数)
|
|||
|
</td>
|
|||
|
</tr>
|
|||
|
|
|||
|
<tr>
|
|||
|
<th>
|
|||
|
二回
|
|||
|
</th>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(20,000)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(20,000)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(30,000)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(40,000)+3月分寮費(2,900×日数)
|
|||
|
</td>
|
|||
|
</tr>
|
|||
|
|
|||
|
<tr>
|
|||
|
<th>
|
|||
|
月払い
|
|||
|
</th>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(20,000)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(20,000)+2月分寮費(84,700)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(30,000)+概算光熱費(84,700)
|
|||
|
</td>
|
|||
|
|
|||
|
<td>
|
|||
|
(12月)光熱費+概算光熱費(40,000)+2月分寮費(84,700)+3月分寮費(2,900×日数)
|
|||
|
</td>
|
|||
|
</tr>
|
|||
|
</table>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li>
|
|||
|
わかったこと <ul>
|
|||
|
<li>
|
|||
|
一括と二回は計算方法が同じ
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
一括と二回は1/16-2/15までは計算方法が同じ
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
<h4>
|
|||
|
必要になるもの
|
|||
|
</h4>
|
|||
|
|
|||
|
<p>
|
|||
|
計算方法の分析ができたので、次は引き落とし金額を求めるのに必要となるデータについて考えた。基本的には、
|
|||
|
</p>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li>
|
|||
|
必要なもの <ul>
|
|||
|
<li>
|
|||
|
B棟なのかC棟なのか?
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
部屋番号(後で個人を特定するために)
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
退寮日
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
12月分光熱費
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
<p>
|
|||
|
ということが判明。『<a href="http://d.hatena.ne.jp/asin/4797336803" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/asin/4797336803', '新版Perl言語プログラミングレッスン入門編');">新版Perl言語プログラミングレッスン入門編</a>』を参考にCSVからデータを吸い上げる方法がわかる。だがここで、退寮日の記述方式が「月/日」という形式だと現状の自分の手には余ると判断。「退寮日」を「退寮する月」と「退寮する日」に分割することでこの問題の回避をはかった。従って、用意するCSVには
|
|||
|
</p>
|
|||
|
|
|||
|
<ol>
|
|||
|
<li>
|
|||
|
CSVファイル <ol>
|
|||
|
<li>
|
|||
|
棟
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
部屋番号
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
退寮する月
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
退寮日
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
12月分光熱費
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
</li>
|
|||
|
</ol>
|
|||
|
|
|||
|
<p>
|
|||
|
という構成にすることにした。このデータはExcelを使えば簡単に作れるだろうから、後はPerlで計算する部分を作る。<span class="footnote"><a href="/sirocco634/#f1" name="fn1" title="「Excelですべて作ってしまえば」という声もあるけれど、何十もの括弧で区切られる数式をいちいちやるのが面倒くさかったりして">*1</a></span>
|
|||
|
</p>
|
|||
|
|
|||
|
<h4>
|
|||
|
はまった部分
|
|||
|
</h4>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li>
|
|||
|
foreach構文の$_の部分(→$_に格納されるのってカウンタじゃなくて、配列の具体的な値なのですね。。。)
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
初歩的だけど、elseifじゃなかったんだ。。。elsif
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
Cygwin上のchompはうまく動かない(改行コードとか文字コードの違いかな?)
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
<h4>
|
|||
|
できたもの
|
|||
|
</h4>
|
|||
|
|
|||
|
<pre class="syntax-highlight">
|
|||
|
<span class="synStatement">use strict</span>;
|
|||
|
<span class="synStatement">use warnings</span>;
|
|||
|
<span class="synComment"># temp.csv を開く。存在しなければ、スクリプトを終了する</span>
|
|||
|
<span class="synStatement">open</span> (<span class="synIdentifier">FILE</span>, <span class="synConstant">'temp.csv'</span>) <span class="synStatement">or</span> <span class="synStatement">die</span> <span class="synConstant">"</span><span class="synIdentifier">$!</span><span class="synConstant">"</span>;
|
|||
|
<span class="synStatement">while</span> (<span class="synStatement">my</span> <span class="synIdentifier">$line</span> = <span class="synIdentifier"><FILE></span>) {
|
|||
|
<span class="synComment"># 一行ずつ読み込んで、@dataに格納する</span>
|
|||
|
<span class="synStatement">my</span> <span class="synIdentifier">@data</span> = <span class="synStatement">split</span>(<span class="synStatement">/</span><span class="synConstant">,</span><span class="synStatement">/</span>, <span class="synIdentifier">$line</span>);
|
|||
|
<span class="synComment"># temp.csvの構造は</span>
|
|||
|
<span class="synComment"># 棟,部屋番号,支払い方法,退寮する月,退寮する日,12月分光熱費</span>
|
|||
|
<span class="synComment"># ちなみに支払い方法:</span>
|
|||
|
<span class="synComment"># 1 : 一括払い 2 : 二回払い 3 : 月払い</span>
|
|||
|
<span class="synComment"># だから、</span>
|
|||
|
<span class="synComment"># @data[0] --> 棟 // @data[1] --> 部屋番号 // @data[2] --> 支払い方法</span>
|
|||
|
<span class="synComment"># @data[3] --> 退寮する月 // @data[4] --> 退寮する日</span>
|
|||
|
<span class="synComment"># @data[5] --> 光熱費</span>
|
|||
|
<span class="synComment"># B棟の人の場合</span>
|
|||
|
<span class="synStatement">if</span> (<span class="synIdentifier">$data</span>[<span class="synConstant"></span>] <span class="synStatement">eq</span> <span class="synConstant">"B"</span>){
|
|||
|
<span class="synStatement">print</span> <span class="synIdentifier">$data</span>[<span class="synConstant"></span>] . <span class="synIdentifier">$data</span>[<span class="synConstant">1</span>] . <span class="synConstant">","</span>;
|
|||
|
<span class="synComment"># 一括と二回は同じ計算式なので、</span>
|
|||
|
<span class="synComment"># ここでは同じものとして扱う</span>
|
|||
|
<span class="synStatement">if</span> (<span class="synIdentifier">$data</span>[<span class="synConstant">2</span>] == <span class="synConstant">1</span> || <span class="synIdentifier">$data</span>[<span class="synConstant">2</span>] == <span class="synConstant">2</span>){
|
|||
|
<span class="synComment"># 1/16~2/15のとき</span>
|
|||
|
<span class="synStatement">if</span> ((<span class="synIdentifier">$data</span>[<span class="synConstant">3</span>] == <span class="synConstant">1</span> && <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>] >= <span class="synConstant">16</span>) || (<span class="synIdentifier">$data</span>[<span class="synConstant">3</span>] == <span class="synConstant">2</span> && <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>] <= <span class="synConstant">15</span>)) {
|
|||
|
<span class="synComment"># 支払う金額は、「10,000 + 12月分光熱費」</span>
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">10000</span> + <span class="synIdentifier">$data</span>[<span class="synConstant">5</span>] . <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
<span class="synComment"># 2/16~2/29のとき</span>
|
|||
|
} <span class="synStatement">elsif</span> (<span class="synIdentifier">$data</span>[<span class="synConstant">3</span>] == <span class="synConstant">2</span> && <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>] <= <span class="synConstant">29</span>) {
|
|||
|
<span class="synComment"># 支払う金額は、「20,000 + 12月分光熱費」</span>
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">20000</span> + <span class="synIdentifier">$data</span>[<span class="synConstant">5</span>] . <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
<span class="synComment"># 3/1~3/15のとき</span>
|
|||
|
} <span class="synStatement">elsif</span> (<span class="synIdentifier">$data</span>[<span class="synConstant">3</span>] == <span class="synConstant">3</span> && <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>] <=<span class="synConstant">15</span>) {
|
|||
|
<span class="synComment"># 支払う金額は、「30,000 + 12月分光熱費 + 3月分寮費」</span>
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">30000</span> + <span class="synIdentifier">$data</span>[<span class="synConstant">5</span>] + (<span class="synConstant">2300</span> * <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>]) . <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
} <span class="synStatement">else</span> {
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">"data out of range!</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
}
|
|||
|
<span class="synComment"># 月払いの時</span>
|
|||
|
} <span class="synStatement">elsif</span> (<span class="synIdentifier">$data</span>[<span class="synConstant">2</span>] ==<span class="synConstant">3</span>) {
|
|||
|
<span class="synComment"># 1/16~1/31の時</span>
|
|||
|
<span class="synStatement">if</span> (<span class="synIdentifier">$data</span>[<span class="synConstant">3</span>] == <span class="synConstant">1</span> && <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>] <= <span class="synConstant">31</span>) {
|
|||
|
<span class="synComment"># 支払う金額は、「10,000 + 12月分光熱費」</span>
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">10000</span> + <span class="synIdentifier">$data</span>[<span class="synConstant">5</span>] . <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
<span class="synComment"># 2/1~2/15のとき</span>
|
|||
|
} <span class="synStatement">elsif</span> (<span class="synIdentifier">$data</span>[<span class="synConstant">3</span>] == <span class="synConstant">2</span> && <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>] <= <span class="synConstant">15</span>) {
|
|||
|
<span class="synComment"># 支払う金額、「10,000 + 66300 + 12月分光熱費」</span>
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">10000</span> + <span class="synConstant">66300</span> + <span class="synIdentifier">$data</span>[<span class="synConstant">5</span>] . <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
<span class="synComment"># 2/16~2/29のとき</span>
|
|||
|
} <span class="synStatement">elsif</span> (<span class="synIdentifier">$data</span>[<span class="synConstant">3</span>] == <span class="synConstant">2</span> && <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>] <= <span class="synConstant">29</span>) {
|
|||
|
<span class="synComment"># 支払う金額は、「20,000 + 66,300 + 12月分光熱費」</span>
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">20000</span> + <span class="synConstant">66300</span> + <span class="synIdentifier">$data</span>[<span class="synConstant">5</span>] . <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
<span class="synComment"># 3/1~3/15のとき</span>
|
|||
|
} <span class="synStatement">elsif</span> (<span class="synIdentifier">$data</span>[<span class="synConstant">3</span>] == <span class="synConstant">3</span> && <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>] <= <span class="synConstant">15</span>){
|
|||
|
<span class="synComment"># 支払う金額は、</span>
|
|||
|
<span class="synComment">#「30,000 + 66,300 + 3月分寮費(2300 * 日数) + 12月分光熱費」</span>
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">30000</span> + <span class="synConstant">66300</span> + (<span class="synConstant">2300</span> * <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>]) + <span class="synIdentifier">$data</span>[<span class="synConstant">5</span>] . <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
} <span class="synStatement">else</span> {
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">"data out of range!</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
<span class="synComment"># C棟の人の場合</span>
|
|||
|
<span class="synStatement">if</span> (<span class="synIdentifier">$data</span>[<span class="synConstant"></span>] <span class="synStatement">eq</span> <span class="synConstant">"C"</span>){
|
|||
|
<span class="synStatement">print</span> <span class="synIdentifier">$data</span>[<span class="synConstant"></span>] . <span class="synIdentifier">$data</span>[<span class="synConstant">1</span>] . <span class="synConstant">","</span>;
|
|||
|
<span class="synComment"># 一括と二回は同じ計算式なので、</span>
|
|||
|
<span class="synComment"># ここでは同じものとして扱う</span>
|
|||
|
<span class="synStatement">if</span> (<span class="synIdentifier">$data</span>[<span class="synConstant">2</span>] == <span class="synConstant">1</span> || <span class="synIdentifier">$data</span>[<span class="synConstant">2</span>] == <span class="synConstant">2</span>){
|
|||
|
<span class="synComment"># 1/16~2/15のとき</span>
|
|||
|
<span class="synStatement">if</span> ((<span class="synIdentifier">$data</span>[<span class="synConstant">3</span>] == <span class="synConstant">1</span> && <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>] >= <span class="synConstant">16</span>) || (<span class="synIdentifier">$data</span>[<span class="synConstant">3</span>] == <span class="synConstant">2</span> && <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>] <= <span class="synConstant">15</span>)) {
|
|||
|
<span class="synComment"># 支払う金額は、「20,000 + 12月分光熱費」</span>
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">20000</span> + <span class="synIdentifier">$data</span>[<span class="synConstant">5</span>] . <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
<span class="synComment"># 2/16~2/29のとき</span>
|
|||
|
} <span class="synStatement">elsif</span> (<span class="synIdentifier">$data</span>[<span class="synConstant">3</span>] == <span class="synConstant">2</span> && <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>] <= <span class="synConstant">29</span>) {
|
|||
|
<span class="synComment"># 支払う金額は、「30,000 + 12月分光熱費」</span>
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">30000</span> + <span class="synIdentifier">$data</span>[<span class="synConstant">5</span>] . <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
<span class="synComment"># 3/1~3/15のとき</span>
|
|||
|
} <span class="synStatement">elsif</span> (<span class="synIdentifier">$data</span>[<span class="synConstant">3</span>] == <span class="synConstant">3</span> && <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>] <=<span class="synConstant">15</span>) {
|
|||
|
<span class="synComment"># 支払う金額は、「40,000 + 12月分光熱費 + 3月分寮費」</span>
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">40000</span> + <span class="synIdentifier">$data</span>[<span class="synConstant">5</span>] + (<span class="synConstant">2900</span> * <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>]) . <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
} <span class="synStatement">else</span> {
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">"data out of range!</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
}
|
|||
|
<span class="synComment"># 月払いの時</span>
|
|||
|
} <span class="synStatement">elsif</span> (<span class="synIdentifier">$data</span>[<span class="synConstant">2</span>] ==<span class="synConstant">3</span>) {
|
|||
|
<span class="synComment"># 1/16~1/31の時</span>
|
|||
|
<span class="synStatement">if</span> (<span class="synIdentifier">$data</span>[<span class="synConstant">3</span>] == <span class="synConstant">1</span> && <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>] <= <span class="synConstant">31</span>) {
|
|||
|
<span class="synComment"># 支払う金額は、「20,000 + 12月分光熱費」</span>
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">20000</span> + <span class="synIdentifier">$data</span>[<span class="synConstant">5</span>] . <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
<span class="synComment"># 2/1~2/15のとき</span>
|
|||
|
} <span class="synStatement">elsif</span> (<span class="synIdentifier">$data</span>[<span class="synConstant">3</span>] == <span class="synConstant">2</span> && <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>] <= <span class="synConstant">15</span>) {
|
|||
|
<span class="synComment"># 支払う金額、「20,000 + 84700 + 12月分光熱費」</span>
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">20000</span> + <span class="synConstant">84700</span> + <span class="synIdentifier">$data</span>[<span class="synConstant">5</span>] . <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
<span class="synComment"># 2/16~2/29のとき</span>
|
|||
|
} <span class="synStatement">elsif</span> (<span class="synIdentifier">$data</span>[<span class="synConstant">3</span>] == <span class="synConstant">2</span> && <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>] <= <span class="synConstant">29</span>) {
|
|||
|
<span class="synComment"># 支払う金額は、「30,000 + 84,700 + 12月分光熱費」</span>
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">30000</span> + <span class="synConstant">84700</span> + <span class="synIdentifier">$data</span>[<span class="synConstant">5</span>] . <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
<span class="synComment"># 3/1~3/15のとき</span>
|
|||
|
} <span class="synStatement">elsif</span> (<span class="synIdentifier">$data</span>[<span class="synConstant">3</span>] == <span class="synConstant">3</span> && <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>] <= <span class="synConstant">15</span>){
|
|||
|
<span class="synComment"># 支払う金額は、</span>
|
|||
|
<span class="synComment">#「40,000 + 84,700 + 3月分寮費(2900 * 日数) + 12月分光熱費」</span>
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">40000</span> + <span class="synConstant">84700</span> + (<span class="synConstant">2900</span> * <span class="synIdentifier">$data</span>[<span class="synConstant">4</span>]) + <span class="synIdentifier">$data</span>[<span class="synConstant">5</span>] . <span class="synConstant">"</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
} <span class="synStatement">else</span> {
|
|||
|
<span class="synStatement">print</span> <span class="synConstant">"data out of range!</span><span class="synSpecial">\n</span><span class="synConstant">"</span>;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
<span class="synStatement">close</span>(<span class="synIdentifier">FILE</span>);
|
|||
|
</pre>
|
|||
|
|
|||
|
<h4>
|
|||
|
今後の課題
|
|||
|
</h4>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li>
|
|||
|
もっとPerlに慣れて早く書けるようになる
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
こういう形で整形するのは便利と言うことがわかったから、もっと勉強してみたい
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
<p>
|
|||
|
こんなのを見つけた:
|
|||
|
</p>
|
|||
|
|
|||
|
<div class="hatena-asin-detail">
|
|||
|
<a href="http://www.amazon.co.jp/dp/4894715589/?tag=hatena_st1-22&ascsubtag=d-7ibv" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://www.amazon.co.jp/dp/4894715589/?tag=hatena_st1-22&ascsubtag=d-7ibv', '');"><img src="https://images-na.ssl-images-amazon.com/images/I/51J7R1J6CYL._SL160_.jpg" class="hatena-asin-detail-image" alt="Perlデータマンジング―データ加工のテクニック集" title="Perlデータマンジング―データ加工のテクニック集" /></a></p>
|
|||
|
|
|||
|
<div class="hatena-asin-detail-info">
|
|||
|
<p class="hatena-asin-detail-title">
|
|||
|
<a href="http://www.amazon.co.jp/dp/4894715589/?tag=hatena_st1-22&ascsubtag=d-7ibv" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://www.amazon.co.jp/dp/4894715589/?tag=hatena_st1-22&ascsubtag=d-7ibv', 'Perlデータマンジング―データ加工のテクニック集');">Perlデータマンジング―データ加工のテクニック集</a>
|
|||
|
</p>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li>
|
|||
|
<span class="hatena-asin-detail-label">作者:</span> <a href="http://d.hatena.ne.jp/keyword/%A5%C7%A5%A4%A5%D3%A5%C3%A5%C9%A5%AF%A5%ED%A5%B9" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%A5%C7%A5%A4%A5%D3%A5%C3%A5%C9%A5%AF%A5%ED%A5%B9', 'デイビッドクロス');" class="keyword">デイビッドクロス</a>,<a href="http://d.hatena.ne.jp/keyword/David%20Cross" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/David%20Cross', 'David Cross');" class="keyword">David Cross</a>,<a href="http://d.hatena.ne.jp/keyword/%B5%DC%C0%EE%C3%A3%C9%A7" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%B5%DC%C0%EE%C3%A3%C9%A7', '宮川達彦');" class="keyword">宮川達彦</a>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<span class="hatena-asin-detail-label">出版社/メーカー:</span> <a href="http://d.hatena.ne.jp/keyword/%A5%D4%A5%A2%A5%BD%A5%F3%A5%A8%A5%C7%A5%E5%A5%B1%A1%BC%A5%B7%A5%E7%A5%F3" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%A5%D4%A5%A2%A5%BD%A5%F3%A5%A8%A5%C7%A5%E5%A5%B1%A1%BC%A5%B7%A5%E7%A5%F3', 'ピアソンエデュケーション');" class="keyword">ピアソンエデュケーション</a>
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<span class="hatena-asin-detail-label">発売日:</span> 2003/01
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<span class="hatena-asin-detail-label">メディア:</span> 単行本
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<span class="hatena-asin-detail-label">購入</span>: 11人 <span class="hatena-asin-detail-label">クリック</span>: 142回
|
|||
|
</li>
|
|||
|
<li>
|
|||
|
<a href="http://d.hatena.ne.jp/asin/4894715589" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/asin/4894715589', 'この商品を含むブログ (26件) を見る');" target="_blank">この商品を含むブログ (26件) を見る</a>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="hatena-asin-detail-foot">
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="footnote">
|
|||
|
<p class="footnote">
|
|||
|
<a href="/sirocco634/#fn1" name="f1">*1</a>:「Excelですべて作ってしまえば」という声もあるけれど、何十もの括弧で区切られる数式をいちいちやるのが面倒くさかったりして
|
|||
|
</p>
|
|||
|
</div>
|