Now when I run communicate.pl I get the output I expect:$ cat > Communicate.pm package Communicate; use 5.010_000; use strict; use warnings; sub build_greeter { my ( $class, $name, $arg ) = @_; return sub { my $person = shift // 'World'; my $comment = $arg->{greeting} // 'Hello'; say sprintf '%s, %s!', $comment, $person; } } use Sub::Exporter -setup => { exports => [ greet => \'build_greeter' ], }; 1; $ cat > communicate.pl #! perl use 5.010_000; use strict; use warnings; use lib '.'; use Communicate greet => { greeting => 'Well-done', -as => 'say_to', }; say_to('Nelo'); exit 0;
Currently the following one-liner works:$ perl communicate.pl Well-done, Nelo!
But I wondering if this could also work with the -m flag to get the same result and if so, how? $ perl -I. -mCommunicate=greet<what would go in here?> -e 'say_to("Nelo")' Thanks =) Ps: This is just to satisfy my curiosity. I could very well use the one-liner as it stands above.$ perl -I. -e 'use Communicate greet => { greeting => q{Good job}, -as + => q{say_to} }; say_to(q{Nelo})' Good job, Nelo!
In reply to Building custom routines with Sub-Exporter using the "-m" flag in a perl one-liner by j1n3l0
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |