phi95aly has asked for the wisdom of the Perl Monks concerning the following question:
problem is, hash values can both have ampersands (&) and equal signs (=) in it, causing this to break. As you can see, each name is appended by the length index of it's value. I'm now trying to write a reg expression that will split this apart based on this length index:my ($name, $value); my @vars = split "&", $data; foreach (@vars) { ($name, $value) = split "="; $hash->{$name} = $value; }
However, this doesnt work because i cant figure out how to reference the length index (captured with $2) in the regex itself. The example i've given above where i simply included $2 as the length match doesnt work. also, each value still ends with an ambersand (&). If i were to include this into the regex it wouldnt match the last value which isnt followed by one. Anybody has an idea how to fix this or a more elegant way to do this. thank you.while ($data =~ /(.*?)\[(\d+)\]=(.{[B]$2[/B]})/g) { $hash->{$1} = $3; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: splitting string based on length index
by ikegami (Patriarch) on Nov 05, 2004 at 22:18 UTC | |
by phi95aly (Novice) on Nov 05, 2004 at 22:39 UTC | |
by tachyon (Chancellor) on Nov 05, 2004 at 23:35 UTC | |
|
Re: splitting string based on length index
by diotalevi (Canon) on Nov 05, 2004 at 22:31 UTC | |
|
Re: splitting string based on length index
by BrowserUk (Patriarch) on Nov 05, 2004 at 23:16 UTC | |
|
Re: splitting string based on length index
by TedPride (Priest) on Nov 06, 2004 at 13:20 UTC |