akagrawal3 has asked for the wisdom of the Perl Monks concerning the following question:

View::Value->new({ name => 'create_key', opt_spec => [qw( host=s #few more values )], db_connection => [qw/ hello /], handler => sub { foo (@_) }, }); sub foo { my @opt = View::Value::get_opt; my %handler_for = ( host => sub { create(@_) }, #few more key, value pair ); sub create { my %opt = @_; # Assume that $key has the public key for my $host (split /,/, $opt{host}) { system qq{cat $key | ssh -q $host 'umask 077; test -d .ssh || + mkdir .ssh ; cat >> .ssh/keys'} } return; }
The function foo() is called through View::Value->new. I think that this code takes command-line argument as well. Let me know if this is the case. Kindly, help me with the following: 1. I am nowhere able to find the routine get_opt. Is it a pre-defined one 2. Will the function create() be called only when I give --host during runtime? 3. Now what values are passed to create() 4. what does that system command mean? what is its order or execution? 5. What is that host=s?

Replies are listed 'Best First'.
Re: run-time arguments
by rovf (Priest) on Mar 01, 2012 at 10:41 UTC
    I think that this code takes run-time argument as well. Let me know if this is the case.
    What is a run-time argument of a function? Or more precises, what other arguments could a function have, if not at run-time? (The alternative would be an argument binding called Currying, but Perl does not support this).
    I am nowhere able to find the routine get_opt
    Neither am I. Hence, the program you posted is either incorrect or incomplete.
    What is that host=s?
    The technically correct answer to this would be it's a string, but I could imagine that the code you are posted is used together with Getopt::Long. This will probably answer your other questions too.

    -- 
    Ronald Fischer <ynnor@mm.st>
      Oops. sorry I meant command-line argument

        Command-line arguments are kept in @ARGV. The code you posted doesn't touch @ARGV, but the code you didn't post (i.e. the contents of View::Value) might.

Re: run-time arguments
by JavaFan (Canon) on Mar 01, 2012 at 10:36 UTC
    I think your questions will not get usable answers until we know more about the package View::Value. Considering that CPAN doesn't seem to have a View::Value module, it seems to be something that's local to your environment.

    Maybe you should talk to the author and/or maintainer of View::Value?

Re: run-time arguments
by Anonymous Monk on Mar 01, 2012 at 10:33 UTC
    Do you know the magic word please? Your questions would sound much less demanding that way. Especially as PerlMonks is no service desk with an agreed service level and with an obligation to answer your questions. (note: being polite to your local service-desk-people is also recommended.)
      I have already asked for help!!! Guess you didnt see that. But I would still not mind using that magic word. Chill out man!!!!