For brevity and clarity in the question: Using the __DATA__ label will enable folks to run this easily.
Update: Agh! the gotcha here is there are some lines with 2 key value pairs on em :(
#!/usr/bin/perl -w use strict; use Data::Dumper; for(grep {/\w/}<DATA>){ # g repeats the regex, e executes the Perl in the substitution, # returns the number of matches into the condition. # $1 and $2 are the bracketed matches in the regex in order. + unless( s/^(^[a-z ]+) *: *([\w\d]+)/$_{$1}=$2/ige ){ chomp; if (/:/){ # key part $_{$_}=join(',',@_); # make new key item @_=() } else { # list part push @_,$_ } } } print Dumper(\%_); __DATA__ Graq: Agnostic: Number: 634321 age: 27 hair colour: black height: 73 weight: 123 legs: 2 arms: 2 jameson bells guinness favourite: detests: likes:
--
Brother Frankus.
¤
In reply to Re: More Regular Expressions (text data handling)
by frankus
in thread More Regular Expressions (text data handling)
by graq
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |