Hello
I want to parse a String with empty spaces to separate fields into a hash:
[code=perl]
use strict;
use warnings;
my $data = 'ACCESS:NO PROXYNAME:local host URL:http://localhost/ MDN:none FREE:YES PAID:NO';
my %values = split(/[: ]/, $data);
foreach my $k (keys %values)
{
print "$k: $values{$k}\n";
}
[/code]
However, the way above did not work as there is two ":" in the pattern "URL:http://localhost/".
It only works when I change it into "URL:http//localhost/" (remove one ":" character). Could you please help
Many thanks
john
I want to parse a String with empty spaces to separate fields into a hash:
[code=perl]
use strict;
use warnings;
my $data = 'ACCESS:NO PROXYNAME:local host URL:http://localhost/ MDN:none FREE:YES PAID:NO';
my %values = split(/[: ]/, $data);
foreach my $k (keys %values)
{
print "$k: $values{$k}\n";
}
[/code]
However, the way above did not work as there is two ":" in the pattern "URL:http://localhost/".
It only works when I change it into "URL:http//localhost/" (remove one ":" character). Could you please help
Many thanks
john
Comment