2014年12月8日星期一

Re: [PerlChina] perl北京聚会——2014年12月7日

把那天的讲稿能分享一下吗?

2014-12-02 12:10 GMT+08:00 chenlin rao <rao.chenlin@gmail.com>:
我注册了一个meetup组: http://www.meetup.com/Beijing-Perl-Mongers/events/219013814/ meetup.com是目前比较流行的一个平台,喜欢聚会分享的可以注册一下看看咯。时不时可能就能看到其他感兴趣的东西有个聚会在离你不远的地方……

ps:注册的时候别用 163.com 邮箱,好像垃圾邮件过多被 meetup.com 拒了。

在 2014年12月2日 上午11:40,Achilles Xu <formalin14@gmail.com>写道:

嗨,各位:

本周末北京举行个perl小聚会。主要由三斗讲一下elasticsearch的ELK套件。其他演讲尚未确定,欢迎自荐。剩下的是讨论环节。欢迎大家参加。

时间:12月7日14:00 —— 18:00
地点:北京市朝阳区中远幸福大厦A座14层   (地铁10号线亮马桥站出来,往北走一点(约300米),路西就是。)
联系人: Achilles Xu   18611952631

最好能先跟邮件或贴报名,当然也欢迎空降。


Achilles Xu
formalin14@gmail.com



--
您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com。
要向此网上论坛发帖,请发送电子邮件至 perlchina@googlegroups.com。
通过以下网址访问此论坛:http://groups.google.com/group/perlchina。
要查看更多选项,请访问 https://groups.google.com/d/optout。

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com。
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com。
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout。

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com。
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com。
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout。

[PerlChina] Re: PerlChina Advent 03: unidecode

Cool

在 2014年12月3日星期三UTC+8下午5时27分33秒,Fayland Lam写道:
# unidecode

虽然 Unicode 已经非常流行,但是有时候在某些场景下,您不得不使用 ASCII 来作为输出。比如

  * 短消息 SMS,某些短消息网关不支持 Unicode
  * 文件名重命名
  * 不知道输入是什么语言,但需要转成能稍微看懂的
  * 等等

这时候您可以使用 [Text::Unidecode](https://metacpan.org/pod/Text::Unidecode) 来帮忙。

    use utf8;
    use Text::Unidecode;
    print unidecode("Léon & møøse\n"); # Leon & moose
    print unidecode("您好"); # Nin Hao
    print unidecode("こんにちは"); # konnitiha

该模块对于某些字符可能支持不够完美,这时候你可以简单地写一个 wrap,参考该模块 [POD](https://metacpan.org/pod/Text::Unidecode) 文档。

## Usage

一个将目录下所有中文名的文件转成对应拼音的脚本:

    use Text::Unidecode;
    use Encode;

    opendir(my $dir, "/some/where/from_dir");
    my @files = grep { -f $_ } readdir($dir);
    closedir($dir);

    foreach my $file (@files) {
        my $to_file = unidecode(decode_utf8($file));
        $to_file =~ s/\s+/\_/g;
        next if $to_file eq $file;

        print "$file -> $to_file\n";
        # do a copy
    }

输入结果大致为:

    夜空中最亮的星.mp3 -> Ye_Kong_Zhong_Zui_Liang_De_Xing_.mp3

## 作者
[Fayland Lam](http://fayland.me/)

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com。
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com。
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout。

Re: [PerlChina] Re: PerlChina Advent Day 1

Thanks.

在 2014年12月8日星期一UTC+8下午12时17分24秒,chenlinux写道:
task里直接用connection->server就可以获得执行task的当前主机的地址。比如:

```perl
task "dltxt" => sub {
    my $host = connection->server;
    download "/var/log/system.log", "./syslog/$host.log";
};
```

在 2014年12月8日 上午11:59,wind.chh <wind...@gmail.com>写道:
正好借地问个问题, Rex里面怎么获得传入的host值,

比如,我在代码里面需要对不同的主机做出不同的动作, Rex传入的主机怎么获取到呢 ?

有段时间没有用Rex了, 不知道有没有更新。

在 2014年12月2日星期二UTC+8上午10时39分58秒,Fayland Lam写道:
Rexify

=for advent_year 2014

=for advent_day 1

=for advent_title Rexify

=for advent_author Chenlin Rao

=encoding utf8

Perl 一直以来都是系统管理员们的好朋友。早在L<09 年的 advent Day 5|../../2009/05/SSHBatch.pod> 上,就介绍过一个 Perl 工具叫 L<SSH::Batch>。随着时代变迁,更完备的集群架构管理工具 Puppet、SaltStack、Ansible 等大行其道。在这方面,Perl 社区也出现了新的项目,这就是 (R)?ex 项目。

(R)?ex 项目的设计以配置管理和部署为核心。这个 (R)? ,可以是 SSH 到远程主机,可以是直接到本地主机,也可以是调用 API 控制各大云平台。

(R)?ex 本身的 DSL 设计,是仿照了 Puppet 的语法。(作者本身是德国一位 IDC 运维,本身手上也有 Puppet 环境)

=head2 资源定义语法示例

=begin code

user "ubuntu";
group frontend => "frontend[01..05]";
sudo TRUE;

desc "Prepare Frontend Server";
task "prepare", group => "frontend", sub {
  pkg "apache2",
    ensure => "latest";

  service "apache2",
    ensure => "started";
};

desc "Keep Configuration in sync";
task "configure", group => "frontend", sub {
  prepare();

  file "/etc/apache2/apache2.conf",
    source    => "files/etc/apache2/apache2.conf",
    on_change => sub { service apache2 => "reload"; };
};

=end code

非常一目了然,之前没用过的人也可以一眼看懂这段配置是要干嘛——安装最新的 apache 软件包,启动 apache 服务,传输本地的 "files/etc/apache2/apache2.conf" 到远程主机的 "/etc/apache2/apache2.conf",然后重载 apache 服务。

=head2 即时运行

如果 Rex 止于这种程度,那么我就建议大家直接使用 Puppet 好了。Puppet 的一个问题:无法即时生效。在 Rex 中,实际就是一个很类似之前 SSH::Batch 的用法:

=begin code

$ rex -qw -H "frontend[01..15] middleware[01..05] db[01..04]" -e "say run 'uptime'"

=end code

=head2 云平台 API

云平台,其实也就是一种 Rex 内部资源,所以其使用方式跟普通的 pkg/file/service/cron/ps/tail 等资源并无不同:

=begin code

use Rex::Commands::Cloud;

user "root";
public_key "/path/to/your/just/created/amazon-public.key";
private_key "/path/to/your/just/downloaded/amazon-private-key.pem";

my $access_key = "your-access-key";
my $secret_access_key = "your-secret-key";

cloud_service "Amazon";
cloud_auth "$access_key", "$secret_access_key";

task "create", sub {
   cloud_instance create => { 
            image_id => "ami-02103876",
            name     => "static01",
            key      => "dev-test",
         };
};

=end code

大家可能注意到上面配置中多了一行 C<use Rex::Commands::Cloud>,事实上大家可以任意自己扩展 Rex::Commands 接口,实现自己的资源(名字空间叫 Rex::Commands 而不是 Rex::Resources,倒也可以说明 Rex 的实质,依然是一个命令执行式的工具)。

事实上,Rex 有专门的 modules.rexify.org 来收集发布各种第三方资源。之前,就有国内的朋友制作了 Rex::Commands::Zabbix2 模块。

=head2 web 界面

任何自动化工具最终都会走向 web 界面展示。Rex 最近用 Mojolicious 框架完成了官方的 JobControl 界面。这里就不占用篇幅了,大家可以自行访问官网文档:L<http://www.rexify.org/howtos/jobcontrol/create_project.html>

最后值得说明的是:Rex 官网有中文同步翻译,地址见 L<http://rex.perl-china.com>

http://perlchina-advent.herokuapp.com/calendar/2014/01/


Thanks

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com。
要发帖到此论坛,请发送电子邮件至perl...@googlegroups.com。
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout。

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com。
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com。
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout。

2014年12月7日星期日

Re: [PerlChina] Re: PerlChina Advent Day 1

task里直接用connection->server就可以获得执行task的当前主机的地址。比如:

```perl
task "dltxt" => sub {
    my $host = connection->server;
    download "/var/log/system.log", "./syslog/$host.log";
};
```

在 2014年12月8日 上午11:59,wind.chh <wind.chh@gmail.com>写道:
正好借地问个问题, Rex里面怎么获得传入的host值,

比如,我在代码里面需要对不同的主机做出不同的动作, Rex传入的主机怎么获取到呢 ?

有段时间没有用Rex了, 不知道有没有更新。

在 2014年12月2日星期二UTC+8上午10时39分58秒,Fayland Lam写道:
Rexify

=for advent_year 2014

=for advent_day 1

=for advent_title Rexify

=for advent_author Chenlin Rao

=encoding utf8

Perl 一直以来都是系统管理员们的好朋友。早在L<09 年的 advent Day 5|../../2009/05/SSHBatch.pod> 上,就介绍过一个 Perl 工具叫 L<SSH::Batch>。随着时代变迁,更完备的集群架构管理工具 Puppet、SaltStack、Ansible 等大行其道。在这方面,Perl 社区也出现了新的项目,这就是 (R)?ex 项目。

(R)?ex 项目的设计以配置管理和部署为核心。这个 (R)? ,可以是 SSH 到远程主机,可以是直接到本地主机,也可以是调用 API 控制各大云平台。

(R)?ex 本身的 DSL 设计,是仿照了 Puppet 的语法。(作者本身是德国一位 IDC 运维,本身手上也有 Puppet 环境)

=head2 资源定义语法示例

=begin code

user "ubuntu";
group frontend => "frontend[01..05]";
sudo TRUE;

desc "Prepare Frontend Server";
task "prepare", group => "frontend", sub {
  pkg "apache2",
    ensure => "latest";

  service "apache2",
    ensure => "started";
};

desc "Keep Configuration in sync";
task "configure", group => "frontend", sub {
  prepare();

  file "/etc/apache2/apache2.conf",
    source    => "files/etc/apache2/apache2.conf",
    on_change => sub { service apache2 => "reload"; };
};

=end code

非常一目了然,之前没用过的人也可以一眼看懂这段配置是要干嘛——安装最新的 apache 软件包,启动 apache 服务,传输本地的 "files/etc/apache2/apache2.conf" 到远程主机的 "/etc/apache2/apache2.conf",然后重载 apache 服务。

=head2 即时运行

如果 Rex 止于这种程度,那么我就建议大家直接使用 Puppet 好了。Puppet 的一个问题:无法即时生效。在 Rex 中,实际就是一个很类似之前 SSH::Batch 的用法:

=begin code

$ rex -qw -H "frontend[01..15] middleware[01..05] db[01..04]" -e "say run 'uptime'"

=end code

=head2 云平台 API

云平台,其实也就是一种 Rex 内部资源,所以其使用方式跟普通的 pkg/file/service/cron/ps/tail 等资源并无不同:

=begin code

use Rex::Commands::Cloud;

user "root";
public_key "/path/to/your/just/created/amazon-public.key";
private_key "/path/to/your/just/downloaded/amazon-private-key.pem";

my $access_key = "your-access-key";
my $secret_access_key = "your-secret-key";

cloud_service "Amazon";
cloud_auth "$access_key", "$secret_access_key";

task "create", sub {
   cloud_instance create => { 
            image_id => "ami-02103876",
            name     => "static01",
            key      => "dev-test",
         };
};

=end code

大家可能注意到上面配置中多了一行 C<use Rex::Commands::Cloud>,事实上大家可以任意自己扩展 Rex::Commands 接口,实现自己的资源(名字空间叫 Rex::Commands 而不是 Rex::Resources,倒也可以说明 Rex 的实质,依然是一个命令执行式的工具)。

事实上,Rex 有专门的 modules.rexify.org 来收集发布各种第三方资源。之前,就有国内的朋友制作了 Rex::Commands::Zabbix2 模块。

=head2 web 界面

任何自动化工具最终都会走向 web 界面展示。Rex 最近用 Mojolicious 框架完成了官方的 JobControl 界面。这里就不占用篇幅了,大家可以自行访问官网文档:L<http://www.rexify.org/howtos/jobcontrol/create_project.html>

最后值得说明的是:Rex 官网有中文同步翻译,地址见 L<http://rex.perl-china.com>

http://perlchina-advent.herokuapp.com/calendar/2014/01/


Thanks

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com。
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com。
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout。

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com。
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com。
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout。

[PerlChina] Re: PerlChina Advent Day 1

正好借地问个问题, Rex里面怎么获得传入的host值,

比如,我在代码里面需要对不同的主机做出不同的动作, Rex传入的主机怎么获取到呢 ?

有段时间没有用Rex了, 不知道有没有更新。

在 2014年12月2日星期二UTC+8上午10时39分58秒,Fayland Lam写道:
Rexify

=for advent_year 2014

=for advent_day 1

=for advent_title Rexify

=for advent_author Chenlin Rao

=encoding utf8

Perl 一直以来都是系统管理员们的好朋友。早在L<09 年的 advent Day 5|../../2009/05/SSHBatch.pod> 上,就介绍过一个 Perl 工具叫 L<SSH::Batch>。随着时代变迁,更完备的集群架构管理工具 Puppet、SaltStack、Ansible 等大行其道。在这方面,Perl 社区也出现了新的项目,这就是 (R)?ex 项目。

(R)?ex 项目的设计以配置管理和部署为核心。这个 (R)? ,可以是 SSH 到远程主机,可以是直接到本地主机,也可以是调用 API 控制各大云平台。

(R)?ex 本身的 DSL 设计,是仿照了 Puppet 的语法。(作者本身是德国一位 IDC 运维,本身手上也有 Puppet 环境)

=head2 资源定义语法示例

=begin code

user "ubuntu";
group frontend => "frontend[01..05]";
sudo TRUE;

desc "Prepare Frontend Server";
task "prepare", group => "frontend", sub {
  pkg "apache2",
    ensure => "latest";

  service "apache2",
    ensure => "started";
};

desc "Keep Configuration in sync";
task "configure", group => "frontend", sub {
  prepare();

  file "/etc/apache2/apache2.conf",
    source    => "files/etc/apache2/apache2.conf",
    on_change => sub { service apache2 => "reload"; };
};

=end code

非常一目了然,之前没用过的人也可以一眼看懂这段配置是要干嘛——安装最新的 apache 软件包,启动 apache 服务,传输本地的 "files/etc/apache2/apache2.conf" 到远程主机的 "/etc/apache2/apache2.conf",然后重载 apache 服务。

=head2 即时运行

如果 Rex 止于这种程度,那么我就建议大家直接使用 Puppet 好了。Puppet 的一个问题:无法即时生效。在 Rex 中,实际就是一个很类似之前 SSH::Batch 的用法:

=begin code

$ rex -qw -H "frontend[01..15] middleware[01..05] db[01..04]" -e "say run 'uptime'"

=end code

=head2 云平台 API

云平台,其实也就是一种 Rex 内部资源,所以其使用方式跟普通的 pkg/file/service/cron/ps/tail 等资源并无不同:

=begin code

use Rex::Commands::Cloud;

user "root";
public_key "/path/to/your/just/created/amazon-public.key";
private_key "/path/to/your/just/downloaded/amazon-private-key.pem";

my $access_key = "your-access-key";
my $secret_access_key = "your-secret-key";

cloud_service "Amazon";
cloud_auth "$access_key", "$secret_access_key";

task "create", sub {
   cloud_instance create => { 
            image_id => "ami-02103876",
            name     => "static01",
            key      => "dev-test",
         };
};

=end code

大家可能注意到上面配置中多了一行 C<use Rex::Commands::Cloud>,事实上大家可以任意自己扩展 Rex::Commands 接口,实现自己的资源(名字空间叫 Rex::Commands 而不是 Rex::Resources,倒也可以说明 Rex 的实质,依然是一个命令执行式的工具)。

事实上,Rex 有专门的 modules.rexify.org 来收集发布各种第三方资源。之前,就有国内的朋友制作了 Rex::Commands::Zabbix2 模块。

=head2 web 界面

任何自动化工具最终都会走向 web 界面展示。Rex 最近用 Mojolicious 框架完成了官方的 JobControl 界面。这里就不占用篇幅了,大家可以自行访问官网文档:L<http://www.rexify.org/howtos/jobcontrol/create_project.html>

最后值得说明的是:Rex 官网有中文同步翻译,地址见 L<http://rex.perl-china.com>

http://perlchina-advent.herokuapp.com/calendar/2014/01/


Thanks

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com。
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com。
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout。

[PerlChina] PerlChina Advent 07: postderef

#  [Perl 5.20] 后缀解引用语法


## 启用 


Perl 5.20 可以使用后缀解引用,因为是新的feature,并不是默认启用的。

所以,需要用


    use v5.20;

    use experimental 'postderef';


来启用。


有人会问,这个并没有默认启用,会不会不稳定? 答案是否定的。请参考 Ricardo Signes 的YAPC 视频(链接2)。


##  语法


### 数组解引用

    

    my $items = ['a'..'z']; # 'a', 'b', 'c' .. 'z'

    

    say "get a whole array";

    say(join '; ',   @$items); # a; b; c; d; ... x; y; z

    say(join '; ',  $items->@*); # same

    

    say "get a value by index";

    say  $$items[1]; # 'b'

    say  $items->[1]; # 'b'

    

    say "get multi values by indexes";

    say(join ';', @$items[2,3]); # 'b; c'

    say(join ';', $items->@[2,3]); # 'b; c'

    

    say "get the largest index in a array"; 

    say $items->$#*; # 25

    say $#$items; # 25

    

    

    say "get indexes and values";

    use DDP; # Data::Priner 

    my %hash_norm = %$items[2,3]; # this is postfix slicing. 

    my %hash_postdef = $items->%[2,3]; # same here

    p %hash_norm; # { 2 => 'c' , 3 => 'd' }

    p %hash_postdef; # { 2 => 'c' , 3 => 'd' }

    

    

你可以试试复制本文中的代码部分,运行一下。什么? 你没有安装Data::Printer?


### 更多


这里只讨论数组解引用,hash ref 的语法类似,当然,scalar ref, subroutine ref 也支持后缀解引用,不过用的相对较少。


完全的用法可以参考下面的链接中的表格。


[Mini-Tutorial: Dereferencing Syntax](http://www.perlmonks.org/?node_id=977408)





## 参考


[perlref](https://metacpan.org/pod/distribution/perl/pod/perlref.pod)


[Perl 5.20: Perl 5 at 20](https://www.youtube.com/watch?v=D1LHFKGHceY)


[Cool new Perl feature: postfix dereferencing](http://perltricks.com/article/68/2014/2/13/Cool-new-Perl-feature--postfix-dereferencing)


## 作者  


* [SWUECHO](https://metacpan.org/author/SWUECHO)


--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com。
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com。
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout。

Re: [PerlChina] 2014年12月14日上海地区Perl爱好者聚会

具体位置在哪?
现在有多少人报名参与了?

在 2014年12月1日 下午12:20,blackjack xu <blackjack.xu@gmail.com>写道:
各位,

上海地区Perl爱好者好久没有聚会了,计划在2014年12月14日10点到13点办一次Perl 爱好者聚会,把上海地区的Perl活动恢复起来。本次活动的内容主要是大家认识一下。基本消费是50元,包括茶和中午的一份快餐。特别欢迎还在上学的同学参加,可以免单。

活动地点基本定在上海体育场 4号地铁站附近,同时方便浦西和浦东的朋友。

请有意参加本次活动的Perl 爱好者通过邮件 xu.hejun@163.com 联系我。

请在邮件中告知 姓名和手机号,方便及时通知活动信息。

我会在或者活动前三天通知活动的具体地址。

另外,也请在perlchian.org上有帐号的朋友将本信息转发到perlchina.org 的上海版上,让更多上海朋友知道。

-Jack

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com。
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com。
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout。

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com。
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com。
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout。