SlideShare uma empresa Scribd logo
1 de 119
Baixar para ler offline
Perl 5.10
Versions of Perl (perlhist)

5.000 17 October 1994

        22 March 2000
5.6.0

        18 July 2002
5.8.0
        31 January 2006
5.8.8

        18 December 2008
5.10
Versions of Perl (perlhist)

5.000 17 October 1994

        22 March 2000
5.6.0

        18 July 2002
5.8.0
        31 January 2006
5.8.8

        18 December 2008
5.10

        ?
6.0
Versions of Perl (perlhist)

5.000 17 October 1994

        22 March 2000
5.6.0

        18 July 2002
5.8.0
        31 January 2006
5.8.8

        18 December 2008
5.10

        Сhristmas
6.0
Versions of Perl (perlhist)

5.000 17 October 1994

        22 March 2000
5.6.0

        18 July 2002
5.8.0
        31 January 2006
5.8.8

        18 December 2008
5.10

        2000
6.0
use
feature
use
feature
qw(




say




switch




state
);
use
feature
qw(




say




switch




state
);

use
feature
quot;:5.10quot;;
use
feature
qw(




say




switch




state
);

use
feature
quot;:5.10quot;;
use
5.10.0;
use
feature
qw(




say




switch




state
);

use
feature
quot;:5.10quot;;
use
v5.10.0;
#!/perl5.10/bin/perl

use
feature
quot;***quot;;
#!/perl5.10/bin/perl

use
feature
quot;sayquot;;
say
quot;Perl
6?quot;;
#!/perl5.10/bin/perl

use
feature
quot;sayquot;;
say
quot;Perl
6?quot;;
no
feature
quot;sayquot;;
>
perl5.10
‐e



quot;use
feature
qw(say);
say
$$;quot;
>
perl5.10
‐e



quot;use
feature
qw(say);
say
$$;quot;


>
perl5.10
‐E
quot;say
$$;quot;
//

defined‐or
my
$a;
my
$b
=
$a
//
2;
say
$b;










2
my
$c
=
0;
my
$d
=
$c
//
3;
say
$d;










0

my
$e
=
0;
my
$f
=
$e
||
4;
say
$f;










4
my
$_;
for
(1..5)
{




my
$_
=
'*';




print;
}














*****
$::_
for
(1..5)
{




my
$_
=
'*';




print
$::_;
}














12345
our
$_;
for
(1..5)
{




our
$_
=
'*';




print
$::_;
}














*****
use
strict
'refs';
my
$x
=
'***';
print
1
if
defined
$$x;
use
strict
'refs';
my
$var
=
'***';
print
defined
$$var




?
'yes'
:
'no';

>
perl5.8.8
test.pl
no

















use
strict
'refs';
my
$var
=
'***';
print
defined
$$var




?
'yes'
:
'no';

>
perl5.10
test.pl
Can't
use
string
(quot;xxxquot;)
as
a

SCALAR
ref
while
quot;strict
refsquot;

in
use
at
test.pl
line
3.







                               

use
feature
'switch';
use
feature
qw(switch
say);

my
$tag
=
'hrpw2008';
given
($tag)
{




when
('hrpw2008')
{








say
'Yes';




}
}
use
feature
qw(switch
say);

my
$tag
=
'hrpw2008';
given
($tag)
{




when
('hrpw2008')
{








say
'Yes';




}




default
{say
'No';}
}
when
(123)

when
($value)

when
(undef)

when
([2001..2100])

when
(/d+/)
when
($_
>
0)

when
(int)

when
(int
$_)

when
(&test_the_value)

when
(test_the_value($_))
given
('hrpw2008')
{




when
(/d+/)
{








say
'digits';








continue;




}




when
(/perl/i)
{








say
'Perl';




}
}
when
($what)

      ==
when
($_
~~
$what)
$left
~~
$right

    ==
$right
~~
$left
use
feature
'state';
sub
counter{




state
$value
=
0;




$value++;




say
$value;
}

counter();












1
counter();












2
counter();












3
Regular Expressions
Named saving parens
my
$date
=
'Thu
15
April
2008';
$date
=~
/




(










w+

)



s+




(










d+

)



s+




(










w+

)



s+




(










d{4})
/x;

say
$1;


















Thu
say
$4;


















2008
Named saving parens
my
$date
=
'Thu
15
April
2008';
$date
=~
/




(?<wday>



w+

)



s+




(?<day>




d+

)



s+




(?<month>


w+

)



s+




(?<year>



d{4})
/x;

say
$+{wday};












Thu
say
$+{year};












2008
Named saving parens
my
$date
=
'Thu
15
April
2008';

$date
=~
s/
 






(?<year>d{4})




/








$+{year}
+
1




/xe;

say
$date;







Thu
15
April
2009
my
$code
=
'my
$value
=
100;
say
$value;';

$code
=~
s/




my

























s*




(?<variable>



$[a‐z]+)


s*




=


























s*




(?<value>






[^;]+


)


s*




;


























s*









(?<other_code>.*?)









(k<variable>)









/$+{other_code}$+{value}/x;

say
$code;


























say
100;
my
$leap_years
=
'1992
1996
2004
2008';

$leap_years
=~
m/




(








?<year>



1



d{3}




)




s*




(








?<year>



2



d{3}




)
/x;

say
$_
for
@{$‐{year}};










1996


































2004
my
$leap_years
=
'1992
1996
2004
2008';

$leap_years
=~
m/




(








?<year>



1



d{3}




)








/gx;

say
$_
for
@{$‐{year}};










1992
my
$leap_years
=
'1992
1996
2004
2008';

$leap_years
=~
m/




(








?<year>



1



d{3}


s*




)+








/gx;

say
$_
for
@{$‐{year}};










1996
use
feature
'say';

my
$expr
=
'1
+
(2
+
(3
+
(4
+
5)
+
6))';

$expr
=~
s/




(












(
















[^()]+












)





















|












(?1)




)




/say
$1;/xge;
Posessive quantifiers

         ?+
         *+
         ++
     {min,
max}+
/


quot;




(?:









[^quot;]++







|









.




)*+


quot;
/x
(?|
...)
my
$re
=
qr/






(d{4})(dd)(dd)



|






(w+),s*(d{4}))
/x;

'20080415'
=~
$re;
say
quot;$1
.
$2
.
$3quot;;

'April,
2008'
=~
$re;
say
quot;$4
.
$5quot;;
my
$re
=
qr/



(?|(d{4})(dd)(dd)



|






(w+),s*(d{4})))
/x;

'20080415'
=~
$re;
say
quot;$1
.
$2
.
$3quot;;

'April,
2008'
=~
$re;
say
quot;$1
.
$2quot;;
g{N}
 gN
g{‐N}
k<named>
  ==
g{named}
K
v
h
V
H
R
R   (?>
     





x0Dx0A?
     


|
     





[
     








x0A‐x0C
     








x85
     








x{2028}
     








x{2029}
     





]
     )
Smart matching



       ~~
$a
~~
$b
   ==
$b
~~
$a
my
$b;




$b
~~
undef

!defined
$b
my
$c
=
'abc';




$c
~~
'abc'

$c
eq
'abc'
my
$c
=
'abc';




$c
~~
/b/

$c
=~
/b/
my
@a
=
(1..3);
my
@b
=
(1..3);



@a
~~
@b

1
==
1
&&
2
==
2
&&
3
==
3
my
@a
=
(1..3);
my
@b
=
(1..3);
my
@c
=
(3..5);

@a
~~
@c

1
==
3
&&
2
==
4
&&
3
==
5
my
@d
=
(123,
'abc');
my
@e
=
(qr/d/,
qr/w/);



@d
~~
@e

123
~~
/d/
&&
'abc'
~~
/w/
my
@f
=
('a'..'f');




@f
~~
'd'

grep
{$_
eq
'd'}
@f
my
@g
=
(1..10);




@g
~~
7

grep
{$_
==
7}
@g
my
@g
=
(1..10);




@g
~~
7.0

grep
{$_
==
7.0}
@g
my
@g
=
(1..10);




@g
~~
'7.0'

grep
{$_
eq
'7.0'}
@g
my
@g
=
(1..10);




@g
~~
/^d$/

grep
{$_
=~
/^d$/}
@g
3.14
~~
'3.14'

3.14
==
'3.14'
3.14
~~
'3.14%'

3.14
==
'3.14%'
sub
subA
{return
2}
sub
subB
{return
2}



subA
~~
subB

subA()
==
subB()
sub
subA
{return
2}
my
$subA1_ref
=
&subA;
my
$subA2_ref
=
&subA;

$subA1_ref
~~
$subA2_ref

$subA1_ref
==
$subA2_ref
sub
subA
{return
2}
my
$subA_ref
=
&subA;



$a
~~
$subA_ref

$subA_ref‐>($a)
sub
subA
{return
2}
my
$subA_ref
=
&subA;



‐1
~~
$subA_ref

$subA_ref‐>(‐1)
my
%h
=
(a
=>
'alpha',









b
=>
'beta');



%h
~~
'a'

exists
$h{'a'}
my
%h
=
(a
=>
'alpha',









b
=>
'beta');
my
@f
=
('a'..'f');

%h
~~
@f

grep
{$_}
@h{@f}
my
%h
=
(a
=>
'alpha',









b
=>
'beta');



%h
~~
/[A‐F]/i

grep
{/[A‐F]/i}
keys
%h
my
%h
=
(a
=>
'alpha',









b
=>
'beta');
my
%hh
=
(b
=>
1,
a
=>
2);

%h
~~
%hh

[sort
keys
%h]
~~
[sort
keys
%hh]
Elements of Perl 6
   in Perl 5.10
Elements of Perl 6
   in Perl 5.10
 and differencies
say
my
$x
=
'HRPW2008';
say
$x;
5.10
my
$x
=
'HRPW2008';
say
$x;

HRPW2008
6
my
$x
=
'HRPW2008';
say
$x;

HRPW2008
5.10
my
$x
=
'HRPW2008';
say
($x);
5.10
my
$x
=
'HRPW2008';
say
($x);

HRPW2008
6
my
$x
=
'HRPW2008';
say
($x);

HRPW2008
6
my
$x
=
'HRPW2008';
say($x);

HRPW2008
6
my
$x
=
'HRPW2008;
$x.say;

HRPW2008
5.10
my
$x
=
'HRPW2008';
$x.say;
5.10
my
$x
=
'HRPW2008';
$x.say;

 String concatenation!
6
my
$x
=
'HRPW2008';
$x.say();

HRPW2008
$_
for
(1..3)
{




say;
}
5.10
for
(1..3)
{




say;
}
1
2
3
6
for
(1..3)
{




say;
}
n
n
n
6
for
(1..3)
{




say
$_;
}
1
2
3
6
for
(1..3)
{




$_.say;
}
1
2
3
6
for
(1..3)
{




.say;
}
1
2
3
switch
5.10, 6
my
$str
=
quot;YAPC::Asiaquot;;

given
($str)
{




when
(/Asia/)
{








say
quot;Asiaquot;




}
}
5.10, 6
my
$str
=
quot;YAPC::Asiaquot;;

given
($str)
{




when
(/Asia/)
{








say
quot;Asiaquot;




}
}
6
my
$str
=
quot;YAPC::Asiaquot;;

given
($str)
{




when
(/Asia/)
{








say
quot;Asiaquot;




}
}
6
my
$str
=
quot;YAPC::Asiaquot;;

given
$str
{




when
/Asia/
{








say
quot;Asiaquot;




}
}
6
my
$str
=
quot;YAPC::Asiaquot;;

given
$str
{




say
quot;Asiaquot;
when
/Asia/

}
state
sub
f
{



state
$c;



say
++$c;
}
sub
f
{



state
$c;



say
++$c;
}
f();
f();
f();
5.10
sub
f
{



state
$c;



say
++$c;
}
f();
f();
f();
1
2
3
6
sub
f
{



state
$c;



say
++$c;
}
f();
f();
f();
1
2
3
sub
f
{



state
$c
=
0;



say
++$c;
}
f();
f();
f();
5.10
sub
f
{



state
$c
=
0;



say
++$c;
}
f();
f();
f();
1
2
3
pugs
sub
f
{



state
$c
=
0;



say
++$c;
}
f();
f();
f();
1
1
1
Croatian Perl Workshop,
Zagreb, 2008

          __END__


Andrew Shitov
mail@andy.sh | http://andy.sh

Mais conteúdo relacionado

Mais de Andrew Shitov

Creating a compiler in Perl 6
Creating a compiler in Perl 6Creating a compiler in Perl 6
Creating a compiler in Perl 6Andrew Shitov
 
Fun with Raspberry PI (and Perl)
Fun with Raspberry PI (and Perl)Fun with Raspberry PI (and Perl)
Fun with Raspberry PI (and Perl)Andrew Shitov
 
Параллельные вычисления в Perl 6
Параллельные вычисления в Perl 6Параллельные вычисления в Perl 6
Параллельные вычисления в Perl 6Andrew Shitov
 
Perl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel ComputingPerl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel ComputingAndrew Shitov
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of SmartmatchAndrew Shitov
 
Perl 7, the story of
Perl 7, the story ofPerl 7, the story of
Perl 7, the story ofAndrew Shitov
 
Язык программирования Go для Perl-программистов
Язык программирования Go для Perl-программистовЯзык программирования Go для Perl-программистов
Язык программирования Go для Perl-программистовAndrew Shitov
 
Как очистить массив
Как очистить массивКак очистить массив
Как очистить массивAndrew Shitov
 
What's new in Perl 5.14
What's new in Perl 5.14What's new in Perl 5.14
What's new in Perl 5.14Andrew Shitov
 
Что нового в Perl 5.14
Что нового в Perl 5.14Что нового в Perl 5.14
Что нового в Perl 5.14Andrew Shitov
 
Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Andrew Shitov
 
There's more than one way to empty it
There's more than one way to empty itThere's more than one way to empty it
There's more than one way to empty itAndrew Shitov
 
How to clean an array
How to clean an arrayHow to clean an array
How to clean an arrayAndrew Shitov
 
Say Perl на весь мир
Say Perl на весь мирSay Perl на весь мир
Say Perl на весь мирAndrew Shitov
 

Mais de Andrew Shitov (20)

Creating a compiler in Perl 6
Creating a compiler in Perl 6Creating a compiler in Perl 6
Creating a compiler in Perl 6
 
Fun with Raspberry PI (and Perl)
Fun with Raspberry PI (and Perl)Fun with Raspberry PI (and Perl)
Fun with Raspberry PI (and Perl)
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
Параллельные вычисления в Perl 6
Параллельные вычисления в Perl 6Параллельные вычисления в Perl 6
Параллельные вычисления в Perl 6
 
AllPerlBooks.com
AllPerlBooks.comAllPerlBooks.com
AllPerlBooks.com
 
Perl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel ComputingPerl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel Computing
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of Smartmatch
 
YAPC::Europe 2013
YAPC::Europe 2013YAPC::Europe 2013
YAPC::Europe 2013
 
Perl 7, the story of
Perl 7, the story ofPerl 7, the story of
Perl 7, the story of
 
Язык программирования Go для Perl-программистов
Язык программирования Go для Perl-программистовЯзык программирования Go для Perl-программистов
Язык программирования Go для Perl-программистов
 
Как очистить массив
Как очистить массивКак очистить массив
Как очистить массив
 
What's new in Perl 5.14
What's new in Perl 5.14What's new in Perl 5.14
What's new in Perl 5.14
 
Что нового в Perl 5.14
Что нового в Perl 5.14Что нового в Perl 5.14
Что нового в Perl 5.14
 
Perl6 grammars
Perl6 grammarsPerl6 grammars
Perl6 grammars
 
Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6
 
There's more than one way to empty it
There's more than one way to empty itThere's more than one way to empty it
There's more than one way to empty it
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
 
How to clean an array
How to clean an arrayHow to clean an array
How to clean an array
 
Perl 5.10 и 5.12
Perl 5.10 и 5.12Perl 5.10 и 5.12
Perl 5.10 и 5.12
 
Say Perl на весь мир
Say Perl на весь мирSay Perl на весь мир
Say Perl на весь мир
 

Perl 5.10