Perl Getopt Using Same Option Multiple Times

后端 未结 1 1819
一向
一向 2021-01-22 13:36

In Perl getopts, is it possible to use the same option multiple times but with different values ? I want to give the user the option of entering different grid coor

相关标签:
1条回答
  • 2021-01-22 14:07

    As documented in Getopts::Long - Options with multiple values:

    #!/usr/bin/perl
    use strict;
    use warnings;
    
    use Getopt::Long;
    
    GetOptions(
        "coords=s" => \my @coords,
    );
    
    print "$_\n" for @coords;
    

    Executed using:

    my_grid.pl --coords=10,12 --coords=-18,30 --coords=4,-25
    

    Outputs:

    10,12
    -18,30
    4,-25
    
    0 讨论(0)
提交回复
热议问题