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
$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
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 =~