U
usenet
Kindly consider this code which builds a hash from associated __DATA__
pairs:
#!/usr/bin/perl
use warnings; use strict;
use Data:
umper;
my %setting;
foreach my $pair(<DATA>) {
$setting{$1} = $2 for ( $pair =~ m{(.*)=(.*)} ); # [yuck??]
}
print Dumper(\%setting); #yeah, it works, but...
__DATA__
user=root
password=easy
hostname=abcxyz
This works. But I'm not really happy with using a "for" loop like that
- it just doesn't seem like the best way to go (but I can't really
explain why; I just kinda linger there and stare at it when I mentally
parse the code).
Is there a better way to do this than using the "for" loop that way?
Thanks!
pairs:
#!/usr/bin/perl
use warnings; use strict;
use Data:
my %setting;
foreach my $pair(<DATA>) {
$setting{$1} = $2 for ( $pair =~ m{(.*)=(.*)} ); # [yuck??]
}
print Dumper(\%setting); #yeah, it works, but...
__DATA__
user=root
password=easy
hostname=abcxyz
This works. But I'm not really happy with using a "for" loop like that
- it just doesn't seem like the best way to go (but I can't really
explain why; I just kinda linger there and stare at it when I mentally
parse the code).
Is there a better way to do this than using the "for" loop that way?
Thanks!