in reply to Parsing issue
This is most of the way there, but it will break if you have quoted commas in any of your values. A better (tho' slower) approach would be to build a real parser using something like Parse::RecDescent.
--#!/usr/bin/perl use strict; use warnings; use Data::Dumper; $_ = 'allow:test1,"@test 2 " deny:test3,test4 password:"123 456"'; my %hash = /(\w+):(.+?)(?:\s+(?=\w+:)|$)/g; foreach (keys %hash) { $hash{$_} = [ split /,/, $hash{$_} ] if $hash{$_} =~ /,/; } print Dumper \%hash;
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Parsing issue
by kabel (Chaplain) on Oct 08, 2002 at 12:34 UTC | |
by davorg (Chancellor) on Oct 08, 2002 at 12:47 UTC | |
by jj808 (Hermit) on Oct 08, 2002 at 13:08 UTC |