in reply to map a hash with a default value or exclude
In the spirit of TIMTOWTDI, here's a method that involves capturing your split() output in an arrayref:
... map { chomp; [split'=']; } <$fh>;
which is subsequently filtered through a second map():
%{$self->{info}} = map { EXPR } map { chomp; [split'=']; } <$fh>;
To exclude a key, EXPR is:
defined $_->[1] ? @$_ : ()
To use a default value (here I've used the string: undef), EXPR is:
$_->[1] //= q{undef}; @$_
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: map a hash with a default value or exclude
by GrandFather (Saint) on Sep 13, 2011 at 03:12 UTC | |
by PrakashK (Pilgrim) on Sep 13, 2011 at 19:09 UTC |