j1n3l0 has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Building custom routines with Sub-Exporter using the "-m" flag in a perl one-liner
by jethro (Monsignor) on Aug 21, 2008 at 15:05 UTC | |
by j1n3l0 (Friar) on Aug 21, 2008 at 16:00 UTC | |
by jethro (Monsignor) on Aug 21, 2008 at 16:45 UTC | |
by j1n3l0 (Friar) on Aug 21, 2008 at 16:48 UTC |