On Mon, 3 Mar 2003, Deb wrote:

> Okay, I'm still struggling.  <sigh>  I just cannot seem to get my mind to
> stop, look, and listen.  Here's some code I'm working on:
>
> ------------------------- 8-< --------------------------------------------
> use strict;
> my %cmdLine;
> my $DBG = 1;
>
> while (<DATA>) {
>       chomp;
>
>       my ($adx, $rest) = (split(/\:/,$_));
>       if ($DBG) {print "\$adx=\t<$adx>\n\$rest=\t<$rest>\n";}
>
>       while ($rest ne "") {
>               my ($opt, $arg, $newRest) = ($rest =~ /\s*([\-a-z]*)\s+([^ 
> ]*)\s+(.*)/);
>               $rest = $newRest;
>               $cmdLine{$opt} = $arg;
>       }
> }
>
> __DATA__
> ten-me-900: -r timbu -x me-900 -h ten-me-900
> hidit: -r tenbu -x networks-users -h hidit
> postal: -x direct -h postal
> pickit: -h pickit -x uncrp -r oakd
>
> ------------------------- 8-< --------------------------------------------

I haven't been following this thread, but I think you want
to get store the option and its argument into the hash.

So, I thought I'd suggest a different point of view.

use strict;
my (%cmdLine);

while (<DATA>)
    {
        chomp;
        my ($adx, $rest, @param);
        ($adx, $rest) = split /:/, $_, 2;
        @param = split / +/, $rest;
        while (@param)
            {
            my ($opt) = shift @param;
            $cmdLine{$opt} = shift @param;
            }
    }

I used to use this logic to move through the command line
parameters. This was before I discovered Getopt

Hope it helps.

George P.

>
> Why doesn't the while loop iterate all of $rest?  I can't seem to figure
> out how to get the loop to act on the entire $rest, and get it into the
> hash.
>
> What am I doing wrong?
>
> Thanks,
>
> d
>
>
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to