SPUG: hash from string

Andy Jacobs andyj at microsoft.com
Wed Jul 12 13:57:52 CDT 2000


You could do:
	%hash = split /\s*[\n=]\s*/, $x;
but this keeps the single quotes, and doesn't like the initial newline in
your example.  But I'm sure you can work out the rest. ;-)

 - Andy

> -----Original Message-----
> From: owner-spug-list at pm.org 
> [mailto:owner-spug-list at pm.org]On Behalf Of
> Peter Dueber
> Sent: Wednesday, July 12, 2000 11:28 AM
> To: spug-list at pm.org
> Subject: SPUG: hash from string
> 
> 
> Anyone have a good technique (maybe using map?) to take a 
> string (with embedded new-lines) 
> like the following:
> 
> $x = "
> 'xyz' = '/export/home'
> 'adfd' = '/usr/there'
> 'ddddd = '/someplace/else'
> etc";
> 
> and directly convert it to a hash equivalent to :
> 
> %hash = ('xyz'  => '/export/home', 
>          'adfd' => '/usr/there', 
>          'ddddd => '/someplace/else',
>          etc.
>         );
>         
> 
> Lost in map space.
> 
> 
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
> - - - - - - -
>      POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
>       Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
>   Replace ACTION by subscribe or unsubscribe, EMAIL by your 
> Email-address
>  For full traffic, use spug-list for LIST ; otherwise use 
> spug-list-digest
>   Seattle Perl Users Group (SPUG) Home Page: 
> http://www.halcyon.com/spug/
> 
> 
> 

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For full traffic, use spug-list for LIST ; otherwise use spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list