1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#!/usr/bin/env perl use warnings; use strict; my $new1 = Term_Choose1->new( { farbe => 'blau', aus => 'Holz' } ); print $new1->choose( { farbe => 'gelb' } ); my $new2 = Term_Choose2->new( { farbe => 'blau', aus => 'Holz' } ); print $new2->choose( { farbe => 'gelb' } ); package Term_Choose1; sub new { my $class = shift; my ( $self ) = @_; return bless $self, $class; } sub choose { my $self = shift; my ( $opt ) = @_; $self = { %$self, %$opt } if defined $opt; $self->{farbe} //= 'grün'; $self->{nummer} //= 34; $self->{aus} //= 'Eisen'; return map { sprintf "%10s : %s\n", $_, $self->{$_} } sort keys %$self; } 1; package Term_Choose2; sub new { my $class = shift; my ( $opt ) = @_; my $defaults = { farbe => 'grün', nummer => 34, aus => 'Eisen' }; my $self = { %$defaults, %{$opt//{}} }; return bless $self, $class; } sub choose { my $self = shift; my ( $opt ) = @_; $self = { %$self, %$opt } if defined $opt; return map { sprintf "%10s : %s\n", $_, $self->{$_} } sort keys %$self; } 1;
1 2 3 4 5 6 7
use WWW::Mechanize; my $mech = WWW::Mechanize->new( onerror => 'hallo' ); my $uri = 'http://www.heise.de'; $mech->get( $uri ); say $mech->content; say "WWWWWW";