Descobrindo a linguagem Perl

Preview:

DESCRIPTION

Conheça um pouco mais sobre a linguagem Perl de programação e tudo que ela tem a oferecer! YAPC::Brasil 2014

Citation preview

Descobrindo a Linguagem Perl

Olá!

@that_garu

Just another Perl hacker

Perl?

Perl.

print''.join('%(pre)s%(num)s %(bot)s on the wall, %(nul)s %(bot)s,\n%(tak)s\n'%(lambda c,b:{'pre' :['','%s %s on the wall.\n\n'%(c,b)][abs(cmp(c,'Ninety-nine'))],'num':c,'nul':c. lower(),'bot':b,'tak':['Go to the store and buy some more... Ninety-nine %s.'%b,'Take one down, pass it around,'] [abs(cmp(x,0))] })((lambda x,o:[(['Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety' ][x/(2*3+4)-2]+'-'+o.lower()).replace('-no more',''),o][int(x<20)])(x,['No more','One','Two','Three','Four','Five', 'Six','Seven','Eight','Nine','Ten','Eleven','Twelve','Thirteen','Fourteen',‘Fifteen','Sixteen','Seventeen','Eighteen', 'Nineteen'][[x,x%10][int(x>=20)]]),'bottle%s of beer'%['','s'][abs(cmp(x,1))]) for x in xrange(99,-1,-1))

d=[30644250780,9003106878,30636278846,66641217692,4501790980, 67124603036,13161973916,66606629920,30642677916,30643069058];a,s= [],$*[0];s.bytes{|b|a<<('%036b'%d[b.chr.to_i]).scan( /\d{6}/)};a.transpose.each{|a|a.join.bytes{|i| print((49==i)?($*[1]||"#"):32.chr)};puts}

use CGI':all';path_info=~/\w+/;$_=`grep -l $& *`.h1($&).escapeHTML$t=param(t) ||`dd<$&`;open F,">$&";print F$t;s/htt\S+|([A-Z]\w+){2,}/a{href,$&},$&/eg; print header,pre"$_<form>",submit,textarea t,$t,9,70

use Dancer; use DateTime; !get '/friday13' => sub { is_friday_the_13th( DateTime->now ); }; !get '/friday13/:year/:month/:day' => sub { my $date = DateTime->new( year => param('year' ), month => param('month'), day => param('day' ), ); ! is_friday_the_13th( $date ); }; !sub is_friday_the_13th { my $date = shift; ! if ($date->day == 13 and $date->day_name eq 'Friday') { return ‘YES!'; } else { return 'NO :('; } } !start;

moderna

multi-plataforma

multi-paradigma

enterprise-ready

Perl.

Perl.Comunidade

CPANmetacpan.org

CPAN Testerscpantesters.org

Perl Mongerspm.org

YAPCYet Another Perl Conference

irc.perl.org1249 usuários, 462 canais

Usuários mais felizes?

http://www.crowdflower.com/blog/2009/05/the-programming-language-with-the-happiest-users

Músicas(sério)

Poesia(mais sério ainda)

my $eyes = "closed"; my $heart = "aching"; my $beloved = "gone"; !!no warnings; !my $love = (); !!open MY, "mind"; foreach ($love) { open MY, $eyes; tell my $mind or open my $eyes; } !do not $fear and do not die; !$i; die "because i love you\n"; !do { $i; sleep($_) } while ( $awake ); !warn "$me" if ($i == $wrong); !bind my $love, $dear and do not exit; for (my $world = "dark") {}; for (my $eyes = "blind") {};

doações & apoios

Send-a-Newbie

Google SoC / Code-in

GNOME Outreach Program for Women

The Perl Foundation

Enlightened Perl Organisation

Japan Perl Association

Websites

Listas de Discussão

Encontros Técnicos++

Encontros Sociais++ Encontros Sociais++ Encontros Sociais++

Fácil de contribuir

Fácil de contribuirsup

er

Perl ♡ Github

Perl 5 em 5 minutos!

use strict; use warnings;

use strict; use warnings; use diagnostics;

print “Alo, Mundo”;

print 4 + 3 * 2;

use Math::Trig; !

print Math::Trig::tan(1);

print “Alo, Mundo”;

print “Alo, Mundo”;sub alo { !

}

sub alo { my ($nome) = @_; print “Alo, $nome”; } !

alo( “YAPC::Brasil” );

package Educado; !

sub alo { my ($nome) = @_; print “Alo, $nome”; } !

1;

use Educado; !

alo( “YAPC::Brasil” );

package Educado; !

sub alo { my ($nome) = @_; print “Alo, $nome”; } !

1;

package Educado; use Moo; !

has ‘nome’, is => ‘ro’, default => ‘Mundo’; !

sub alo { my ($self) = @_; print “Alo, “ . $self->nome; } !

1;

use Educado; !

my $obj = Educado->new; !

!

!

print $obj->alo;

use Educado; !

my $obj = Educado->new( nome => ‘YAPC’, ); !

print $obj->alo;

sub alo { my ($nome) = @_; if ($nome eq ‘YAPC’) { foreach my $area (‘NA’, ‘EU’, ‘Asia’, 'Brasil’) { print “Alo, YAPC::” . $area; } } else { print “Alo, $nome”; } }

Snippets!

use autodie; open my $fh, '<', 'arquivo.txt'; !

while (my $linha = <$fh>) { print $linha; } close $fh;

use autodie; open my $fh, ‘>', 'arquivo.txt'; !

print $fh 'Alô, mundo!'; !

close $fh;

use Net::Twitter::Search; !

my $busca = Net::Twitter::Search->new; !

$busca->search(‘Perl')->{results}; !

foreach my $result ( @$busca ) { say $result->{text}; }

!use WWW::Mechanize;my $mech = WWW::Mechanize->new; !$mech->get( 'http://www.exemplo.com' ); !$mech->follow_link( text => 'download' ); !$mech->submit_form( with_fields => { nome => 'Meu Nome’, linguagem => ‘Perl!', });

!

use Spreadsheet::Read; !

# planilha pode ser em .csv, .xls, .ods, .sxc... my $data = ReadData( 'data.xlsx' ); !

# primeira planilha, campo A3 say $sheet->[1]{'A3'};

use Dancer; !get ‘/:nome' => sub { “Olá, ". param(‘nome'); }; !!start;

use Dancer; use DateTime; !get '/friday13' => sub { is_friday_the_13th( DateTime->now ); }; !get '/friday13/:year/:month/:day' => sub { my $date = DateTime->new( year => param('year' ), month => param('month'), day => param('day' ), ); ! is_friday_the_13th( $date ); }; !sub is_friday_the_13th { my $date = shift; ! if ($date->day == 13 and $date->day_name eq 'Friday') { return ‘YES!'; } else { return 'NO :('; } } !start;

perldoc.perl.org

perldoc Meu::Modulo

perldoc -f função

http://onyxneon.com/books/modern_perl/

Recommended