Más contenido relacionado La actualidad más candente (20) Similar a Introduction to Modern Perl (20) Introduction to Modern Perl101. Can lead to subtle bugs when not localised correctly 102. Can now use my $_ to create a lexically scoped variable called $_ 134. {-1} is the last capture buffer 137. – Vertical white space 191. $_ = 'cat'; $new = s/cat/dog/r'; # $_ remains 'cat' 225. “How can I expand variables in text strings?” 253. time – seconds since 1st Jan 1970 344. You may as well make each column VARCHAR(255) 385. sub get_object { my ($class, $id) = @_; if (my $obj = find_obj_in_db($id)) { return $obj; } else { return; } } 387. my $obj = MyClass->get_object(100); print $obj->name; # error 391. sub get_object { my ($class, $id) = @_; if (my $obj = find_obj_in_db($id)) { return $obj; } else { die “No object found with id: $id”; } } 394. my $obj = eval { MyClass->get_object(100) }; if ($@) { # handle exception... } else { print $obj->name; # error } 396. sub get_object { my ($class, $id) = @_; if (my $obj = find_obj_in_db($id)) { return $obj; } else { die MyException->new( type => 'obj_not_found', id => $id, ); } } 398. try { ... } catch ($e) { ... } 434. $p3d = Point3D->new(x => 1, y => 2, z => 3); 444. has 'name' => ( is => 'rw', reader => 'get_name', writer => 'set_name', ); 478. $ perl -MFatal=open -E'open my $fh, "notthere"' Can't open(GLOB(0x86357a4), notthere): No such file or directory at (eval 1) line 4 main::__ANON__('GLOB(0x86357a4)', 'notthere') called at -e line 1 490. try { open my $fh, '<', 'not-there'; } catch ($e) { warn 'Error opening ', $e->args->[-1], ""; warn 'File: ', $e->file, ""; warn 'Function: ', $e->function, ""; warn 'Package: ', $e->package, ""; warn 'Caller: ', $e->caller, ""; warn 'Line: ', $e->line, ""; } 515. $ catalyst.pl CD created "CD" created "CD/script" created "CD/lib" created "CD/root" ... many more ... 521. $ CD/script/cd_server.pl ... lots of output [info] CD powered by Catalyst 5.7015 You can connect to your server at http://localhost:3000 532. sub index :Path :Args(0) { my ( $self, $c ) = @_; # Hello World $c->response_body($c->welcome_message); } 566. Plack is a reference implementation (based on Ruby's Rack) 570. Hard to move an application between server architectures 596. $ plackup app.psgi HTTP::Server::PSGI: Accepting connections at http://localhost:5000/ 598. use Plack::Request; use Data::Dumper; my $app = sub { my $req = Plack::Request->new(shift); return [ 200, [ 'Content-type', 'text/plain' ], [ Dumper $req ], ]; } 600. use Plack::Request; use Plack::Response; use Data::Dumper; my $app = sub { my $req = Plack::Request->new(shift); my $res = Plack::Response->new(200); $res->content_type('text/plain'); $res->body(Dumper $req); return $res->finalize; } 632. Most of the frameworks and server you use already support PSGI 643. Perl is a powerful and flexible programming language 644. Perl is a great way to get your job done