オブジェクト表示-基本サブウインドウ
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
// 初期化関数はウインドウ作成前に実行されるのでWIN_IDを確定することができない。
int init()
{
return(0);
}
// 終了関数はいらない。サブウインドウと一緒にまとめて処理されるから
int deinit()
{
return(0);
}
// スタート関数
int start()
{
//サブウインドウバージョンはこちらでオブジェクトを生成する
int win_idx = WindowFind("ShowMTF0_subw");
if( win_idx < 0) return(- 1);
//int win_idx = 0; // ウィンドウ番号0はメインウインドウ
// ラベル用オブジェクトの生成
ObjectCreate("Label0", OBJ_LABEL, win_idx, 0, 0);
ObjectSet("Label0", OBJPROP_CORNER, 3);
ObjectSet("Label0", OBJPROP_XDISTANCE, 1);
ObjectSet("Label0", OBJPROP_YDISTANCE, 18);
ObjectSetText("Label0", "MACD M15 H1 D1", 8, "Arial", Black);
// 日足チャート用オブジェクトの生成
ObjectCreate("Label1", OBJ_LABEL, win_idx, 0, 0);
ObjectSet("Label1", OBJPROP_CORNER, 3);
ObjectSet("Label1", OBJPROP_XDISTANCE, 1);
ObjectSet("Label1", OBJPROP_YDISTANCE, 1);
// 日足チャートMACD
double macd_d1 = iMACD(NULL, PERIOD_D1, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 0);
if(macd_d1 > 0) ObjectSetText("Label1", CharToStr(221), 16, "Wingdings", Blue);
else ObjectSetText("Label1", CharToStr(222), 16, "Wingdings", Red);
return(0);
}
オブジェクト表示-基本メインウインドウ
#property indicator_chart_window
// 初期化関数
int init()
{
int win_idx = 0; // ウィンドウ番号
// ラベル用オブジェクトの生成 左上
ObjectCreate("Label0", OBJ_LABEL, win_idx, 0, 0);
ObjectSet("Label0", OBJPROP_CORNER, 3);
ObjectSet("Label0", OBJPROP_XDISTANCE, 1);
ObjectSet("Label0", OBJPROP_YDISTANCE, 18);
ObjectSetText("Label0", "MACD M15 H1 D1", 8, "Arial", Black);
// 日足チャート用オブジェクトの生成
ObjectCreate("Label1", OBJ_LABEL, win_idx, 0, 0);
ObjectSet("Label1", OBJPROP_CORNER, 3);
ObjectSet("Label1", OBJPROP_XDISTANCE, 1);
ObjectSet("Label1", OBJPROP_YDISTANCE, 1);
return(0);
}
// 終了関数
int deinit()
{
ObjectDelete("Label0");
ObjectDelete("Label1");
return(0);
}
// スタート関数
int start()
{
// 日足チャートMACD
double macd_d1 = iMACD(NULL, PERIOD_D1, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 0);
if(macd_d1 > 0) ObjectSetText("Label1", CharToStr(221), 16, "Wingdings", Blue);
else ObjectSetText("Label1", CharToStr(222), 16, "Wingdings", Red);
return(0);
}
Treebuilder utf8対策済み
#!/usr/bin/env perl use strict; use warnings; use utf8; use Encode; use HTML::TreeBuilder; binmode STDOUT, ':encoding(cp932)'; binmode STDERR, ':encoding(cp932)'; #use encoding "cp932"; my $html=<<'HTML'; <html> <head> <title>Test Page</title> </head> <body> <div id="content"> <h1>Test Page</h1> <h2>主なトピックス</h2> <ul class="clr"> <li><span class="dateRight">8月30日</span><a href="/topics/title1.html">Title1<\ /a></li> <li><span class="dateRight">8月29日</span><a href="/topics/title2.html">Title2<\ /a></li> <li><span class="dateRight">8月28日</span><a href="/topics/title3.html" class="\ newTitle">Title3</a></li> <li><span class="dateRight">8月27日</span><a href="/topics/title4.html">Title4<\ /a></li> </ul> </div> </body> </html> HTML
#ヒアドキュメントのEOD行には改行のみ入力できる。タブもスペースも入れちゃダメ!!
my $tree = HTML::TreeBuilder->new; $tree->parse($html); my @items = $tree ->look_down('id', 'content') ->look_down('class', 'clr') ->find('li'); for @items{ print $_->as_text."\n" ; } # 8月30日Title1 # 8月29日Title2 # 8月28日Title3 # 8月27日Title4
"cancelled"文字列が存在する行をスルーしてファイル読み込みする。
while(<IN>){ chomp; next if($_ =~/cancelled/); #イコールとチルダを離してはダメ! print OUT $_."\n";
WWW::Mechanize とりあえず完成!
use strict; use warnings; use WWW::Mechanize; use HTML::TreeBuilder; use utf8; use Encode; binmode STDOUT, ':utf8'; sub say {print @_, "\n";} open(IN, '<:encoding(utf8)', 'word_list.txt'); open(OUT, ">word_list_output.txt"); while(<IN>){ chomp; my ($word) = split(/,/, $_); #split リストコンテキストにしないと文字列として認識してくれない my $mech = WWW::Mechanize->new(); $mech->agent_alias( 'Windows IE 6' ); $mech->get('http://eow.alc.co.jp/serch'); print $word."\n\n"; # 検索フォームに単語を入力してサブミット $mech->submit_form( fields => { q => "$word", } ) or die 'submitting failed'; my $res = $mech->content; my $tree = HTML::TreeBuilder->new; $tree->parse($res); $tree->look_down('class', 'wordclass'); my @items =$tree->find('tag', 'ol'); my $input_wd = encode('utf8',$items[0]->as_text); #外から入ってきたものを変換してperl内部で処理する #処理はprintやsplitなどを指す print OUT $word."\t"; print OUT $input_wd."\n"; $tree->delete; }; close(IN); close(OUT);
ファイル入力用のutf8 設定 と リテラル設定
use utf8; binmode STDOUT, ':utf8'; #出口用の追加設定 open my $fh, '<:encoding(utf8)', 'data.txt' #入り口用設定 or die "failed to open file: $!"; my $text = <$fh>; my @text = split //, $text; for (@text) { say $_; } close $fh; ########################################################## use utf8; binmode STDOUT, ':utf8'; #追加設定 my $text = 'Perl入学式'; my @text = split //, $text; for (@text) { say $_; }
CSV流し込み ハッシュによるtempメモリー
my %data = (); open(IN, 'customer_data_win2.csv'); while(<IN>){ chomp; my ($id, $name, $age, $ken, $shi) = split(/,/, $_); # 人データを作る my $people = [$id, $name, $age]; # 結果配列に保存する push(@{$data{$ken}{$shi}}, $people); }
コード一気に読み込む Slurpモジュールでも同じ
my $text = do {local $/; <$fh>;};
my $text = do {local $/ = undef; #改行デリミタをリセット
<$fh>;
};