> -----Original Message-----
> From: p sena [mailto:senapati2...@yahoo.com]
> Sent: 05 March 2011 05:34
> To: perl-win32-users@listserv.ActiveState.com; Brian Raven
> Subject: RE: regex like option *values*
>>>>> __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

Your first idea can be made simpler by choosing a different separator, as comma 
is already being used as a separator for the contents of your square brackets. 
A unique separator means that you only need to call split to get the individual 
strings that you want to expand.

Your second idea can also be simpler. For example...

my @list;
GetOptions('list=s' => sub {push @list, expand_string($_[1]);});

HTH


--
Brian Raven




Please consider the environment before printing this e-mail.

This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient or have received this e-mail in error, please advise 
the sender immediately by reply e-mail and delete this message and any 
attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to