Re: chomp hash keys?
- From: "Dr.Ruud" <rvtol+news@xxxxxxxxxxxx>
- Date: Sat, 29 Apr 2006 19:54:56 +0200
Uri Guttman schreef:
Ruud:
my $sep = qr/ \s* : \s* /x;
my %person = map { chomp; split $sep } <DATA>;
my %hash = map /(.+)$sep(.+)$/, <DATA>
[...]
my %config = read_file( $file ) =~ /^(\w+)=(.+)$/mg ;
nary a chomp in sight!
OK, let me rewrite that with map.
#!/usr/bin/perl
use strict;
use warnings;
my %config = map /^(\w+)=(.+)$/, <DATA>;
print "keys: @{[keys %config]}\n";
while ((my $key, my $value) = each %config) {
print "$key\t=> $value\n";
}
__DATA__
#comment-1
[block]
#comment-2=1+1
ones=11111
twos=222
example=1+2=3
ones=1
Viva that TIMTOWTDI.
--
Affijn, Ruud
"Gewoon is een tijger."
.
- References:
- chomp hash keys?
- From: usenet
- Re: chomp hash keys?
- From: Dr.Ruud
- Re: chomp hash keys?
- From: Uri Guttman
- chomp hash keys?
- Prev by Date: Perl script does not work
- Next by Date: Re: Perl script does not work
- Previous by thread: Re: chomp hash keys?
- Next by thread: Detecting filehandles
- Index(es):
Relevant Pages
|