in reply to Regular expression double grouping negation headache
Maybe I am missing the point here, but if you were using split you wound't have to use any of these regexen. (m/(.+?)=(.+)/ as seen above isn't a nice way of dealing with this..) To abstract your problem: You want to eat up everything until an equal sign, and then the rest of the parameter being the key; If there is no equal sign take the entire argument as a key without value. Here's my solution:
my %d; foreach (@ARGV) { my ($k, $v) = split (m/=/, $_, 2); $d{$k} = (defined $v ? $v : ""); } #this is for checking only.. foreach (keys %d) { print "$_:" . $d{$_} . "\n"; }
And it does the job.. If you would rather stick to your own code, you might modify it to liik like this:
my $defaults = {}; %defaults = map {(($_ =~ /([^\=]+)\=(.+)/)?($1 => $2):($_ => ''))} @AR +GV; print join(",", keys %defaults);
Regards,
-octo-
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Regular expression double grouping negation headache
by blakem (Monsignor) on Jun 30, 2002 at 09:29 UTC |