SPUG: hash from string

Andrew Sweger andy at n2h2.com
Wed Jul 12 13:50:42 CDT 2000


This comes close:

%hash = split /\n|\s*=\s*/, $x;

And this cleans it up a little bit:

%hash = map /'(.*)'/, split /\n|\s*=\s*/, $x;

On Jul 12, 2000 @ 11:28am, Peter Dueber wrote:

> 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.
>         );

-- 
 Andrew Sweger <andy at n2h2.com>   |  N2H2, Incorporated
 Systems Architect               |  900 Fourth Avenue, Suite 3400
 Advanced Technologies Division  |  Seattle WA 98164-1059
 v=206.336.2947  f=206.336.1541  |  http://www.n2h2.com/


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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