1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
use warnings; use 5.14.0; use utf8; package My_Package; use Exporter 'import'; our @EXPORT_OK = qw(my_random); sub my_random { my ( $list, $option ) = @_; binmode STDOUT, ":encoding($option->{encoding_stdout})"; my $rand_element = $list->[rand @$list]; say $rand_element; return $rand_element; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/env perl use warnings; use 5.12.0; use utf8; use lib '.'; use My_Package qw(my_random); my $stdout_encoding = 'UTF-8'; binmode STDOUT, ":encoding($stdout_encoding)"; my $rand_element = my_random( [ qw( eins zwei drei vier fünf ) ], { encoding_stdout => $stdout_encoding } );