> > >> __DATA__
> > >> abc0[1-9].ctr.[pad,spd].set.in
> > >> abc[01-22].ctr.[pad,spd].set.in
> > >> abcL[1,2,3].ctr.[pad,spd].set.in
> > >> abcL[1,2,3].ctr.[pad,spd].set.in
> > >> abcL[1,2,3].ctr.[70,001].set.in
> > >>
> > ---------------------------------------------------
> > >>
> > >> It should work for lists of ranges, and
> ranges of
> > strings as well as
> > >> numbers.
> > >>
> > >> Regarding incorporating into Getopt::Long,
> see the
> > Tips and Tricks
> > >> section of the doco.
> 
> Brian,
> 
> Can this solution be generalized in a way to support
> --option_value=abc0[1-9].ctr.[pad,spd].set.in,xxx0[2-8].mmm.[rst,spd].afr.org
> types?
> Means those _DATA_ lines all appear in one line separated
> by comma as above (instead of newline separated). Should it
> be efficient to do in the expand_string() or from the main
> while iteration just before calling expand_string.

Replying back with a solution I can see. In case of such option value supplies 
it becomes difficlut to do the similar thing as below-
GetOptions ("library=s" => \@libfiles);
           @libfiles = split(/,/,join(',',@libfiles));

Such mixed strings can be parsed and returned as a list as below. In our 
context, to be called from the main before the while iteration. After that this 
list's elems can be passed on to the expand_xxx routine(s) one by one.

# Arg-> A string which is the option value like
#abc0[1-9].ctr.[pad,spd].set.in,xxx0[2-8].mmm.[rst,spd].afr.org,<some more 
values...>
sub parse_mix_strings {
    my @x = split (//, $_[0]);
    my $bracket_close;
    my $bracket_open;
    my @elems;
    my @hstrings;
    for (@x) {
        push @elems, $_;
        if ($_ eq '[') {
            $bracket_open = 1;
        }
        if ($_ eq ']') {
            if ($bracket_open == 1) {
                $bracket_close = 1;
                $bracket_open = 0;
            }
        }
        if ($_ eq ',' && !$bracket_open && $bracket_close) {
            $elems[$#elems] =~ s/,//;
            push @hstrings, join("",@elems);
            @elems = ();
        }

    }
    push @hstrings, join("", @elems);
    return@hstrings;
}

On *another note* leveraging use of the Getopts::Long can be this way I think ?

my %list;
GetOptions('list=s%' =>
                      sub { print "1 = $_[1] 2 = $_[2]\n"; 
push(@{$list{$_[1]}}, expand_string($_[2])) });

print "Elems = ", scalar @{$list->{add}}, "\n"; # debug
print "> ", @{$list{add}}, "\n"; # debug
<skip>

And program can be called as - <prog_name.pl> --list add=abc0[1-2].src.spd.in 
--list add=volvo[1-5].jeep.sch.edu


~TIA


      
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to