APM: One liner to get hash from an environment list

Wayne Walker wwalker at bybent.com
Wed Jan 21 23:36:46 CST 2004


Someone pointed out the %config = %ENV; solution.  The point was a small
clean config file parser.  we used env to generate shell type config
data as an example, not for actual application of the concept.

This is more clearly useful to those who weren't at the meeting.  Boom,
no foreach loop, nothing complex.

%config = map { /(.*?)=['"]?(.*)['"]?/ } qx(cat /etc/defaults/some_prog_env.sh);

This should parse any valid bourne shell syntax key=value config file
into a hash.

On Wed, Jan 21, 2004 at 09:20:06PM -0600, Mark Lehmann wrote:
> We used this in the meeting Wednesday evening.  I learned this from Bill
> Raty.
> 
> %config = map { /(.*?)=(.*)/ } qx(env);
> 
> 
> -- 
> Mark Lehmannn
> mlehmann at marklehmann.com - mobile 512 689-7705
> 
> 
> 
> 
> _______________________________________________
> Austin mailing list
> Austin at mail.pm.org
> http://mail.pm.org/mailman/listinfo/austin

-- 

Wayne Walker
wwalker at bybent.com                 Do you use Linux?!
http://www.bybent.com              Get Counted!  http://counter.li.org/
Perl - http://www.perl.org/        Perl User Groups - http://www.pm.org/
Jabber IM:  wwalker at jabber.phototropia.org       AIM:     lwwalkerbybent



More information about the Austin mailing list