Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Descobrindo a linguagem Perl

Avatar for garux garux
September 19, 2014

Descobrindo a linguagem Perl

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

Avatar for garux

garux

September 19, 2014
Tweet

More Decks by garux

Other Decks in Programming

Transcript

  1. 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))
  2. 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;
  3. 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") {};
  4. package Educado; ! sub alo { my ($nome) = @_;

    print “Alo, $nome”; } ! 1;
  5. package Educado; ! sub alo { my ($nome) = @_;

    print “Alo, $nome”; } ! 1;
  6. package Educado; use Moo; ! has ‘nome’, is => ‘ro’,

    default => ‘Mundo’; ! sub alo { my ($self) = @_; print “Alo, “ . $self->nome; } ! 1;
  7. sub alo { my ($nome) = @_; if ($nome eq

    ‘YAPC’) { foreach my $area (‘NA’, ‘EU’, ‘Asia’, 'Brasil’) { print “Alo, YAPC::” . $area; } } else { print “Alo, $nome”; } }
  8. use autodie; open my $fh, '<', 'arquivo.txt'; ! while (my

    $linha = <$fh>) { print $linha; } close $fh;
  9. ! 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!', });
  10. ! use Spreadsheet::Read; ! # planilha pode ser em .csv,

    .xls, .ods, .sxc... my $data = ReadData( 'data.xlsx' ); ! # primeira planilha, campo A3 say $sheet->[1]{'A3'};
  11. use Dancer; ! get ‘/:nome' => sub { “Olá, ".

    param(‘nome'); }; ! ! start;
  12. 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;