SlideShare uma empresa Scribd logo
1 de 39
mantovani@perl.org.br
São Paulo Perl Monger
Yet Another Perl Conference
Introdução ao Perl
Daniel de O. Mantovani
Aware
mantovani@perl.org.br
São Paulo Perl Monger
Perl
Linguagem ?
Cultura ?
História ?
Comunidade ?
Matemática ?
Filosofia ?
Inglês ?
Física ?
Biologia ?
Ler Senhor dos Anéis ?
Foo ?
Bar ?
mantovani@perl.org.br
São Paulo Perl Monger
WTF ?
mantovani@perl.org.br
São Paulo Perl Monger
Senhor dos Anéis
O brian d foy disse que ler Senhor Dos Anéis
ajuda a entender o código fonte do Perl.
mantovani@perl.org.br
São Paulo Perl Monger
Filosofia
O André acabou de falar que filosifa ajudou muito
ele a entender lógica.
mantovani@perl.org.br
São Paulo Perl Monger
Faça isso divertido
O Larry Wall programa Perl porque Perl é
divertido, meus amigos e eu também.
mantovani@perl.org.br
São Paulo Perl Monger
Leitura
Programadores lêem muito
Nenhuma outra área no mundo, muda tão
rápido
mantovani@perl.org.br
São Paulo Perl Monger
Smart Questions
Leitura gera dúvida ;)
How To Ask Questions The Smart Way
mantovani@perl.org.br
São Paulo Perl Monger
Perl
free-form language
o/
DWIM
Do What I Mean
o/
/o/
o
mantovani@perl.org.br
São Paulo Perl Monger
Seu Melhor Amigo “Ever”
perldoc
mantovani@perl.org.br
São Paulo Perl Monger
perldoc perl
man perl
mantovani@perl.org.br
São Paulo Perl Monger
A-E-I-O-U
A-E-I-O-U
mantovani@perl.org.br
São Paulo Perl Monger
Perl tem 7 tipos de variáveis
Variáveis
mantovani@perl.org.br
São Paulo Perl Monger
Scalar
Array
Hash
Filehandle
Typeglob
Format
Sub
perldoc perldata
mantovani@perl.org.br
São Paulo Perl Monger
Perl tem 6 tipos de variáveis :D
Variáveis
mantovani@perl.org.br
São Paulo Perl Monger
Scalar
Array
Hash
Filehandle
Typeglob
Format
Sub
perldoc perldata
mantovani@perl.org.br
São Paulo Perl Monger
Scalar
my $var = 'foo'
print “$varn”;
mantovani@perl.org.br
São Paulo Perl Monger
Array
@foo = (1,2,3,4,5,6,7,8,9,10);
@foo = 1 .. 10; #range operator
print $foo[-1]
print $foo[0]
mantovani@perl.org.br
São Paulo Perl Monger
Hash
%foo = (bar =>1, baz => 2);
print $foo{bar};
$foo{value} = 3;
@foo{1 .. 10} = 1 .. 10;
mantovani@perl.org.br
São Paulo Perl Monger
Filehandle
Descritor de arquivo
open my $filehandle, '<', meuarquivo.txt
open FILEHANDLE,'<', meuarquivo.txt
my @array = <$fh>
{$='';$var=<$fh>}
while (my $line = <$fh>){ print $line}
mantovani@perl.org.br
São Paulo Perl Monger
Typeglob
$foo = 1;
@foo = (1 .. 10);
%foo = (1 .. 10);
open foo,'<',arquivo.txt;
sub foo { return “hi” };
*foo;
mantovani@perl.org.br
São Paulo Perl Monger
Format
Não se usa mais Format
Perl6::Form
$text = form " =================================== ",
"| NAME | AGE | ID NUMBER |",
"|----------+------------+-----------|",
"| {<<<<<<} | {||||||||} | {>>>>>>>} |",
$name, $age, $ID;
mantovani@perl.org.br
São Paulo Perl Monger
Scope
my
local
our
mantovani@perl.org.br
São Paulo Perl Monger
Subroutines
sub foo {
my $valor = shift || 'vazio';
print “$valorn”
}
@_ #mágica
mantovani@perl.org.br
São Paulo Perl Monger
Chamando
foo(“teste”)
&foo
foo “teste”
&foo(“teste”)
mantovani@perl.org.br
São Paulo Perl Monger
IF
if ( .. ) {}
elsif (..) {}
else {}
print “Tenho uma var” if $var
mantovani@perl.org.br
São Paulo Perl Monger
Given
given($foo) {
when ("foo") {
say '$foo is the string "foo"';
}
when (&complicated_check) {
say 'a complicated check for $foo is true';
}
default {
die q(I don't know what to do with $foo);
}
mantovani@perl.org.br
São Paulo Perl Monger
Iterators
foreach my $foo (1..10) {
print “$foon”;
}
for (my $i = 0;$i <= 10;$i++) {
print “$in”;
}
my @foo = grep {$_ % 2 == 0} 1 .. 10
my %hash = map {}
print for 1 .. 10;
mantovani@perl.org.br
São Paulo Perl Monger
grep/map
my @foo = grep {$_ % 2 == 0} 1 .. 10
for(@foo) {
$foo[$i] = $_ if($_ % 2 == 0);
}
%hash = map { get_a_key_for($_) => $_ } @array;
%hash = ();
foreach (@array) {
$hash{get_a_key_for($_)} = $_;
}
mantovani@perl.org.br
São Paulo Perl Monger
Loop
while(1+1) {
print “O loop ainda nao acaboun”;
}
mantovani@perl.org.br
São Paulo Perl Monger
Context
Perl tem 3 tipos de contexto
Void, Scalar, e List
mantovani@perl.org.br
São Paulo Perl Monger
map { .. } 1 .. 10
&foo
Void
mantovani@perl.org.br
São Paulo Perl Monger
my $foo = 1;
Scalar
mantovani@perl.org.br
São Paulo Perl Monger
Um array é uma lista mas uma lista não é um
array.
List
mantovani@perl.org.br
São Paulo Perl Monger
Você não pode usar métodos modificadores em
uma lista.
push (1,2,3,4,5) #errado
print ((1,2,3,4,5)[0]) #primeiro elemento
Contexto de lista
mantovani@perl.org.br
São Paulo Perl Monger
Ainda lista
my $foo = (1,2,3,4,5);
Retorna sempre o valor mais a direita
my @foo = 1 .. 10;
$foo = @foo;
Retorna o tanto de elementos do array
mantovani@perl.org.br
São Paulo Perl Monger
Intro
perldoc perlintro ;)
mantovani@perl.org.br
São Paulo Perl Monger
:D
Não esqueça, se divirta
mantovani@perl.org.br
São Paulo Perl Monger
Dúvidas ?
sao-paulo.pm.org/lista
irc.perl.org #sao-paulo.pm
Você pode perguntar aqui ^

Mais conteúdo relacionado

Destaque

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Destaque (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

Introdução ao perl