4. Синтаксис package Point; use Moose; has 'x' => (is => 'rw' , isa => 'Int' ); has 'y' => (is => 'rw' , isa => 'Int' ); sub clear { my $self = shift ; $self->x(0); $self->y(0); }
5. Однострочники # Change all the isolated oldvar occurrences to newvar perl -i.old -pe 's{oldvar}{newvar}g' *.pl # Find palindromes perl -lne 'print if $_ eq reverse' /usr/dict/words # Command-line that reverse all the bytes in a file perl -e 'print scalar reverse <>' f1 f2 f3 ... # Remove all blank lines. perl -ne 'print unless /^$/' # Print prime numbers perl -wle '(1 x $_) !~ /^(11+?)+$/ && print while ++$_'
6.
7. Net::XMPP use Net::XMPP; my $xmpp = new Net::XMPP::Client(); $xmpp->SetCallBacks( message => amp;InMessage); $xmpp->Execute( hostname => 'talk.google.com' , port => 5222, username => 'user@gmail.com' , password => 'passw' , resource => 'Messenger' , ); $xmpp->Disconnect();
8. Net::Oscar use Net::OSCAR qw(:standard) ; sub im_in { my ($oscar, $sender, $message, $is_away) = @_; print "[AWAY] " if $is_away; print "$sender: $message" ; } $oscar = Net::OSCAR->new(); $oscar->set_callback_im_in(amp;im_in); $oscar->signon($screenname, $password); while (1) { $oscar->do_one_loop(); }
9. AI::NeuralNet::BackProp # Create a new network with 1 layer, 5 inputs, # and 5 outputs. my $net = new AI::NeuralNet::BackProp(1, 5, 5); # Add a small amount of randomness to the network $net->random(0.001); # Demonstrate a simple learn() call my @inputs = ( 0, 0, 1, 1, 1, ); my @ouputs = ( 1, 0, 1, 0, 1, ); print $net->learn(inputs, outputs), "" ;
10. Mojolicious use Mojolicious::Lite; # Route with placeholder get '/:foo' => sub { my $self = shift ; my $foo = $self->param( 'foo' ); $self->render(text => "Hello from $foo!" ); }; app->start;