spln2016:diario1
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
spln2016:diario1 [2016/02/18 20:58] – created ambs | spln2016:diario1 [2016/02/18 21:58] (current) – [Diário de Bordo - Aula 1 - 2016-02-15] ambs | ||
---|---|---|---|
Line 31: | Line 31: | ||
-Call centers, siri, QA (Question Answering) | -Call centers, siri, QA (Question Answering) | ||
- | Prática: | + | === Prática |
necessário ter perl versão 5.14 ou mais | necessário ter perl versão 5.14 ou mais | ||
para windows existe a possibilidade de utilizar o strawberry perl | para windows existe a possibilidade de utilizar o strawberry perl | ||
- | -script para contar palavras | + | |
- | -instalação de modulos para o perl | + | -instalação de modulos para o perl |
- | + | ||
- | + | ||
- | + | ||
- | Exercicíos Perl: | + | |
- | + | ||
- | # | + | |
- | + | ||
- | use warnings; | + | |
- | use strict; #para dar os warnings e erros para nos ajudar a perceber o que se está a passar | + | |
- | use utf8::all; #para usar o encoding utf8 para todos os inputs | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | # --------------------------------------- | + | |
- | + | ||
- | my $y = 20; #my é utilizado para declarar variáveis locais, para var globais utiliza-se o our | + | |
- | print " | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | # --------------------------------------- Contar as linhas de um input ----------------------------------------------- | + | |
- | + | ||
- | my ($l,$c); | + | |
- | while ($l = <>){ #<> - operador diamante vai ler o input, o diamante vazio permite receber ficheiros, já < | + | |
- | c++; | + | |
- | } | + | |
- | + | ||
- | print "$c linhas\n"; | + | |
+ | === Exercicíos Perl === | ||
+ | # | ||
+ | | ||
+ | use warnings; | ||
+ | use strict; # para dar os warnings e erros para nos ajudar a perceber o que se está a passar | ||
+ | use utf8::all; # para usar o encoding utf8 para todos os inputs | ||
+ | === Exemplo de declaração de uma variável === | ||
- | # --------------------------------------- Exercicío com a var $_ ----------------------------------------------------- | + | my $y = 20; # my é utilizado para declarar variáveis locais |
+ | # para var globais utiliza-se o our | ||
+ | print " | ||
- | #se não guardarmos o que é lido em nenhuma variável ele vai para a var $_ | + | === Contar as linhas de um input === |
- | my ($c); | + | |
- | while (<>){ | + | |
- | print $_; | + | |
- | | + | |
- | | + | |
- | } | + | |
- | print "$c linhas\n"; | + | my ($l,$c); |
+ | while ($l = <>) { | ||
+ | # <> - operador diamante vai ler o input, o diamante vazio permite receber ficheiros, | ||
+ | # já < | ||
+ | | ||
+ | } | ||
+ | |||
+ | | ||
+ | === Exercicío com a var $_ === | ||
+ | # se não guardarmos o que é lido em nenhuma variável ele vai para a var $_ | ||
+ | my ($c); | ||
+ | while (<> | ||
+ | print $_; | ||
+ | print; # a var $_ pode ser omitida | ||
+ | $c++; | ||
+ | } | ||
+ | | ||
+ | print "$c linhas\n"; | ||
- | # --------------------------------------- Contar palavras -------------------------------------------------------------- | ||
- | my ($c); | + | === Contar palavras === |
- | while (<> | + | |
- | while ($_ =~ /\w+/g) { #utilizamos expressões regulares para identificar o que é uma palavra, as letros inseridas depois das barras são modificadores, | + | |
- | $c++; | + | |
- | } | + | |
- | } | + | |
- | print "$c palavras\n"; | + | my ($c); |
+ | while (<>) { | ||
+ | while ($_ =~ /\w+/g) { | ||
+ | # utilizamos expressões regulares para identificar o que é uma palavra, | ||
+ | # as letras inseridas depois das barras são modificadores, | ||
+ | # neste caso o g é utilizado para fazer o match à palavra | ||
+ | # quantas vezes forem possiveis na string | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | | ||
+ | |||
+ | |||
+ | |
spln2016/diario1.1455825487.txt.gz · Last modified: 2016/02/18 20:58 by ambs