Leser: 37
1 2 3 4 5 6 7 8 9 10 11 12 13
use strict; use warnings; use 5.018; package jjj; sub YYY { my $y = shift // q{ ~ \o/ ~ /o\ ~ \o/ }; say $y; } 1;
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 43 44 45 46 47
use strict; use warnings; use 5.018; my %dispatch = ( lach => \&Booh::laugh, foo => \&main::bar, bar => \&baz, yipp =>\&jjj::YYY, ); require "jjj.pl"; package Booh; sub laugh { my $lach = shift // 'hahahahahahah'; say $lach; } 1; package main; sub bar { my $knete = shift // 'is nich'; say "Bar $knete aus der Kasse"; } sub baz { say 'Bar und Baaaatz'; } ########## my $coderef = Booh->can('laugh'); $coderef->('hihia'); # Boo::laugh(....) $dispatch{lach}->('Gacker!!!!!!!!!!!!!!!'); # auch Boo::laugh(....) $coderef = main->can('bar'); $coderef->(); $coderef->('100 EURO'); $coderef = jjj->can('YYY'); $coderef->(); $coderef->('Yippi'); $dispatch{'yipp'}->('hollaaaaaa'); 1;
1 2 3 4 5 6 7 8
use strict; use warnings; use feature 'say'; say "Perl $]"; my $vor = jjj->can('YYY'); say "vor require: ",!defined($vor)?"undef":$vor; require "jjj.pl" and say "require"; my $nach = jjj->can('YYY'); say "nach require: ",!defined($nach)?"undef":$nach; 1;;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/usr/bin/perl use strict; use warnings; if (1==1) { require 'test2.pl'; } print 'vorher: '.main->can('test')."\n"; require 'test2.pl'; print 'nachher: '.main->can('test')."\n"; { package testtest; require 'test2.pl'; } testtest::test();
1 2 3 4 5 6 7
use strict; use warnings; sub test { print "Hallo\n"; } return '1';