Someone on alt.perl asked:
What is elegant way of convert string like "--param1 blabla --param2 bla bla blo" Into assoc array $a{"param1"} == blabla and $a{"param2"}== "bla bla blo" ? Param values never starts with "--".
Here's my reply.
my $string = "--param1 blabla --param2 bla bla blo"; my %newhash = $string =~ /--(\w+)\s+(.*?(?=\s*$|\s*--))/g; for (sort keys %newhash) { print "$_ = <$newhash{$_}>\n"; }

Replies are listed 'Best First'.
Re: &bull;extract options from a simple string
by svad (Pilgrim) on Jul 01, 2002 at 14:28 UTC
    Here is another one, which may be of interest in a light of that task: alternate parsing method for options
    I start 80% of my small utilities programs with that lines and found them convenient enough.

    Best wishes,
    svad

      Ahh, but that one's looking at an already split @ARGV, for which there are dozens of solutions (even some I've hand-rolled). The poster wanted something that comes from a single string.

      -- Randal L. Schwartz, Perl hacker

        I definitively need glasses if I'm going to read that code snippet...or a bigger monitor...

        #!s #!s, oh baby when she moves, she moves...