<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>憂藍夢境‧部落格 &#187; perl</title>
	<atom:link href="http://blog.linym.net/archives/tag/perl/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.linym.net</link>
	<description>我的學習心得、筆記</description>
	<lastBuildDate>Fri, 09 Dec 2011 12:33:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>[Perl] Port Scanner</title>
		<link>http://blog.linym.net/archives/93</link>
		<comments>http://blog.linym.net/archives/93#comments</comments>
		<pubDate>Tue, 02 May 2006 10:33:15 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/93</guid>
		<description><![CDATA[這是課堂上練習的程式，可以掃瞄某主機哪些 Port 有開放。 利用 Perl::Socket 建立 socket 後 connent() 主機，如果回應 true 表示連線正確 (Port 有開啟)。 使用方法： portscan.pl &#60;主機名稱&#62; #!/usr/bin/perl use strict; use Socket; my $host = shift; print &#34;Enter scan port start:&#34;; my $port = &#60;&#62;; print &#34;Enter scan port end:&#34;; my $port_end = &#60;&#62;; my $protocol = getprotobyname(&#039;tcp&#039;); $host = inet_aton($host) or die &#34;$host failed&#34;; [...]]]></description>
			<content:encoded><![CDATA[<p>這是課堂上練習的程式，可以掃瞄某主機哪些 Port 有開放。<br />
利用 Perl::Socket 建立 socket 後 connent() 主機，如果回應 true 表示連線正確 (Port 有開啟)。<br />
使用方法：<br />
portscan.pl &lt;主機名稱&gt;</p>
<pre title="code" class="c">

#!/usr/bin/perl
use strict;
use Socket;

my $host = shift;
print &quot;Enter scan port start:&quot;;
my $port = &lt;&gt;;
print &quot;Enter scan port end:&quot;;
my $port_end = &lt;&gt;;

my $protocol = getprotobyname(&#039;tcp&#039;);
$host = inet_aton($host) or die &quot;$host failed&quot;;

for (my $i = $port; $i &lt;= $port_end; $i++) {
    socket(SOCK , AF_INET , SOCK_STREAM , $protocol) or die &quot;socket() failed: $!&quot;;
    my $dest_addr = sockaddr_in($i , $host);
    if (connect(SOCK , $dest_addr)) {
        print &quot;Port: $i is open\n&quot;;
    }
    close SOCK;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/93/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用文言文寫 Perl</title>
		<link>http://blog.linym.net/archives/83</link>
		<comments>http://blog.linym.net/archives/83#comments</comments>
		<pubDate>Fri, 14 Apr 2006 08:28:16 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/83</guid>
		<description><![CDATA[詳情請看這篇討論串 真是服了這位高人，讓 Perl 可以用文言文寫 目前這個 module 已經放上 CPAN，名稱為「Lingua::Sinica::PerlYuYan」 有興趣的可以試看看。 不過我想對現代人來說，英文應該是比文言文好懂吧!]]></description>
			<content:encoded><![CDATA[<p><a href="http://groups.google.com/group/tw.bbs.comp.lang.perl/browse_thread/thread/f0f95423c7cd71c5/bb1374f3f8cf10cf">詳情請看這篇討論串</a></p>
<p>真是服了這位高人，讓 Perl 可以用文言文寫<br />
目前這個 module 已經放上 CPAN，名稱為「<a href="http://search.cpan.org/%7Eautrijus/Lingua-Sinica-PerlYuYan-0.03/PerlYuYan.pm">Lingua::Sinica::PerlYuYan</a>」<br />
有興趣的可以試看看。<br />
不過我想對現代人來說，英文應該是比文言文好懂吧! </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/83/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[作業­2] 由檔案讀取成績並計算平均 - Perl</title>
		<link>http://blog.linym.net/archives/79</link>
		<comments>http://blog.linym.net/archives/79#comments</comments>
		<pubDate>Tue, 14 Mar 2006 10:45:14 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/79</guid>
		<description><![CDATA[功能說明： 讀取成績檔內容並計算平均，最後寫入新檔。 成績資料檔：testdata.txt (檔名改為 testdata) 實作： #!/usr/bin/perl use strict; open FILE, &#34;testdata&#34; or die &#34;Can not open file: $!&#34;; my @lines; foreach (&#60;FILE&#62;) { chomp; split(/__/); my @grades = split(/,/, $_[1]); my $total = 0; my $average = 0; foreach my $grade (@grades) { $total += $grade; } $average = $total/@grades; my $line = $_[0].&#039;__&#039;.$_[1].&#039;=&#62;&#039;.$average.&#34;\n&#34;; [...]]]></description>
			<content:encoded><![CDATA[<p>功能說明：</p>
<blockquote><p>讀取成績檔內容並計算平均，最後寫入新檔。<br />
成績資料檔：<a href="http://blog.linym.net/wp-content/uploads/2006/04/testdata.txt">testdata.txt</a> (檔名改為 testdata)</p></blockquote>
<p>實作：</p>
<pre title="code" class="c">

#!/usr/bin/perl
use strict; 

open FILE, &quot;testdata&quot; or die &quot;Can not open file: $!&quot;; 

my @lines;
foreach (&lt;FILE&gt;) {
    chomp;
    split(/__/);
    my @grades = split(/,/, $_[1]);
    my $total = 0;
    my $average = 0;
    foreach my $grade (@grades) {
        $total += $grade;
    }
    $average = $total/@grades;
    my $line = $_[0].&#039;__&#039;.$_[1].&#039;=&gt;&#039;.$average.&quot;\n&quot;;
    push @lines, $line;
} 

open OUT_FILE, &quot;&gt;testdata2&quot; or die &quot;Can not open file: $!&quot;;
print OUT_FILE @lines; 

close FILE;
close OUT_FILE;
</pre>
<p><strong>筆記：</strong><br />
chop 和 chomp 的差異。<br />
這兩個都可以刪除尾端的換行字元，但使用 chomp 是比較安全的，因為 chop 會把尾端是 0 的一併刪除，造成錯誤結果。 </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/79/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[作業­1] 串列與陣列練習 - Perl</title>
		<link>http://blog.linym.net/archives/77</link>
		<comments>http://blog.linym.net/archives/77#comments</comments>
		<pubDate>Tue, 14 Mar 2006 10:44:27 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/77</guid>
		<description><![CDATA[題目： 1. 試著把串列 (24, 33, 65, 42, 58, 24, 87) 放入陣列中，並讓使用者輸入索引值 (0…6)，然後印出陣列中相對應的值。 2. 把剛剛的陣列進行排序，並且印出排序後的結果。 3. 取出陣列中大於40的所有值。 4. 將所有陣列中的值除以 10 後印出。 實作： #!/usr/bin/perl use strict; my @array = (24, 33, 65, 42, 58, 24, 87); while (1) { print &#34;1) Select No.1 \n&#34;; print &#34;2) Select No.2 \n&#34;; print &#34;3) Select No.3 \n&#34;; print &#34;4) Select [...]]]></description>
			<content:encoded><![CDATA[<p>題目：</p>
<blockquote><p>1. 試著把串列 (24, 33, 65, 42, 58, 24, 87) 放入陣列中，並讓使用者輸入索引值 (0…6)，然後印出陣列中相對應的值。<br />
2. 把剛剛的陣列進行排序，並且印出排序後的結果。<br />
3. 取出陣列中大於40的所有值。<br />
4. 將所有陣列中的值除以 10 後印出。</p></blockquote>
<p>實作：</p>
<pre title="code" class="c">

#!/usr/bin/perl
use strict; 

my @array = (24, 33, 65, 42, 58, 24, 87); 

while (1) {
    print &quot;1) Select No.1 \n&quot;;
    print &quot;2) Select No.2 \n&quot;;
    print &quot;3) Select No.3 \n&quot;;
    print &quot;4) Select No.4 \n&quot;;
    print &#039;Please enter a number: &#039;; chomp($_ = &lt;&gt;); 

    if ($_ == 1) {
        while (1) {
            print &quot;Please enter 0-6 (&#039;q&#039; to exit): &quot;;
            chomp($_ = &lt;&gt;);
            last if ($_ eq &#039;q&#039;);
            print $array[$_].&quot;\n&quot;;
        }
    } elsif ($_ == 2) {
        my @array_sort = sort(@array);
        print &quot;$_\t&quot; for @array_sort;
        print &quot;\n&quot;;
    } elsif ($_ == 3) {
        my @sift = grep {$_ &gt; 40} @array;
        print &quot;$_\t&quot; for @sift;
        print &quot;\n&quot;
    } elsif ($_ == 4) {
        my @answer = map {$_ / 10} @array;
        print &quot;$_\t&quot; for @answer;
        print &quot;\n&quot;;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/77/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

