parsing long strings

2005-09-02 Thread Tom Allison
I have a really long string that looks like 'toDNExtension:, toDNFailure:, ' and I want to parse it into key/value pairs... I tried: foreach ( $string =~ /([\w\s]+):([\w\s]+)/g ) { ... } But I always get only the last pair... I thought the /g would stop that behaviour.. -- To

Re: parsing long strings

2005-09-02 Thread Jeff Pan
$strings='toDNExtension:, toDNFailure:,'; foreach (split/,\s*/,$strings) { $hash{(split/:/,$_)[0]} = (split/:/,$_)[1]; } is this useful? On Fri, 2 Sep 2005 09:41:54 -0400 (EDT), Tom Allison [EMAIL PROTECTED] said: I have a really long string that looks like

Re: parsing long strings

2005-09-02 Thread Jeff 'japhy' Pinyan
On Sep 2, Tom Allison said: foreach ( $string =~ /([\w\s]+):([\w\s]+)/g ) { ... } But I always get only the last pair... I thought the /g would stop that behaviour.. You're mixing 'foreach' with /.../g, and the results aren't what you'll expect. Instead, use 'while': while ($str =~