Marcos wrote..

>Marcos Lorenzo <[EMAIL PROTECTED]> wrote [5:10pm +0100]
>
>ML> I've been trying for an hour or so to use Getopt::Long, but I just
don't
>ML> get it... I've been reading FAQ's & docs but I need some more examples
to
>ML> know how it works.
>ML>
>ML> Well, I want to process arguments like:
>ML>
>ML> perl command.pl arg_needed [ --flag1 one=something two=otherthing |
--flag2 | --flag3 ]
>ML>
>ML> and I get:
>ML>
>ML> $var=arg_needed
>ML> $one=something
>ML> $two=otherthing
>ML>
>ML>
>ML> How can I achieve this?
>ML>
>ML> TIA,
>ML> m4c.
>
>OK, more info:
>
>I have a script with:
>
>my %ifconfig=();
>GetOptions(\%ifconfig, "set=s%");
>while (($clave,%valor)= each %ifconfig){
>   print "\t$clave\t->\n";
>   while (($clave2,$valor2)=each %valor){
>      print "\t\t$clave2\t->\t$valor2\n";
>   }
>}
>
>And I run:
>
>c:\temp>perl command.pl -s dasdas=dasdas
>        set     ->
>                HASH(0x1c2513c) ->
>
>Why I can't get
>
>set->
>dasdas->dasdas
>???

Your '($clave,%valor) = each %ifconfig' statement doesn't work as you
expect. 'each' will only EVER return two scalars. You need to first capture
the scalar and THEN dereference it in the 'clave2/valor2' loop. So with two
changes to your code you're closer to your goal:

  no strict;
  use warnings;

  use Getopt::Long;

  my %ifconfig=();
  GetOptions(\%ifconfig, "set=s%");
  while (($clave,$valor)= each %ifconfig){
     print "\t$clave\t->\n";
     while (($clave2,$valor2)=each %$valor){
        print "\t\t$clave2\t->\t$valor2\n";
     }
  }

Note: this still requires multiple '--set' options, which is not what you
originally asked for. Ie. you still have to call:

  perl command.pl -s a=1 -s b=2

And you can't just call

  perl command.pl -s a=1 b=2

Fact is that Getopt::Long is written to reproduce common command line option
formats, and your format is not a common one, so as Randy demonstrates, you
may need to write your own handler.

-- 
  Jason King
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to