This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
sub get_fib_with_initvals { | |
my ($first, $second) = @_; | |
# Perl の代入は右結合なので、 my $fib = sub { ... } で右辺に $fib があってはいけない。 | |
# この場合、宣言と代入を分けて書く必要がある | |
my $fib; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# 2019/03/14 | |
# inurl - 標準入力を peco に渡して、URL がある行を選択するとその URL をブラウザで開く | |
use strict; | |
use warnings; | |
use IPC::Open2; | |
my (@url, $child_out, $child_in); | |
open2 $child_out, $child_in, 'peco'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# backup-clipboard.pl | |
# 実行するとクリップボードを監視して、対象とする Markdown だと思ったら | |
# 雑に /tmp 以下にダンプする | |
use strict; | |
use warnings; | |
use AnyEvent; | |
use AnyEvent::Mac::Pasteboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use v5.14; | |
use strict; | |
use warnings; | |
use utf8; | |
binmode 'STDOUT', ':utf8'; | |
# JSON::PP はバイト列ではなく内部文字を返すので decode が必要 | |
# ただ perldoc JSON::PP を読むと枝葉が自動的に内部文字になるようにしてくれるオプションはありそう(あんまり読んでいない) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# N回サイコロを振ったときの出る目の全ての場合を割り出して期待値を計算する | |
use strict; | |
use warnings; | |
use List::Util qw(sum); | |
use constant BONUS_TRIO1 => 10_000; | |
use constant BONUS_TRIO456 => 2_000; | |
use constant DEBUG => $ENV{DEBUG}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ perl -e 'for (1..50) { my $n = "3" x $_ . "1"; system "factor", $n; }' | |
31: 31 | |
331: 331 | |
3331: 3331 | |
33331: 33331 | |
333331: 333331 | |
3333331: 3333331 | |
33333331: 33333331 | |
333333331: 17 19607843 | |
3333333331: 673 4952947 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# smtp-connect-bench.pl [HOSTNAME|IPADDR] | |
# SMTP 接続の速度を確認する | |
use strict; | |
use warnings; | |
use Net::SMTP; | |
use Time::HiRes qw(time sleep); # ミリ秒化 | |
use constant WAIT_SECONDS => 15; | |
use constant SMTP_TIMEOUT_SECONDS => 120; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use utf8; # このスクリプトは UTF-8 で書かれている、文字列リテラルはそういう文字として評価する | |
use Encode qw(encode decode); | |
binmode STDOUT, ':utf8'; | |
# https://www.post.japanpost.jp/zipcode/dl/kogaki-zip.html | |
my $file = 'KEN_ALL.CSV'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# \r を使って文字のパラパラまんが的なもの | |
use strict; | |
use warnings; | |
use Time::HiRes qw(sleep); | |
# 標準出力は \n を送らないとバッファリングして画面に表示してくれないことがあるので、バッファリングしないでねという指示 | |
$| = 1; # STDOUT のバッファリングをオフにしてほしい |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# 2018/06/21 xtetsuji | |
# Dropbox と iCloud で片方にしか無い、または両方にあるファイルを色分け | |
# このスクリプトでは WEB+DB PRESS と Software Design で調査する | |
# | |
# iCloud で、クラウド側にはファイルはあるけれど手元にデータを | |
# 同期していない場合、foo.txt の代わりに .foo.txt.icloud というファイルが | |
# 置かれることに注意 | |
use strict; |