SPUG: hash from string
Peter Dueber
peter at hivnet.fhcrc.org
Wed Jul 12 16:58:12 CDT 2000
Something interesting:
If one strips off leading and trailing whitespace AND the quotes, this works for both
cases ('ddd' = 'dkdkdkd' or 2='dkd kdkdk'):
$x =~ s/^\s+|\s+$|'//g;
%hash = split /\n|\s*=\s*/, $x;
no map, both cases, ie, works for:
$x = "
'xyz' = '/export/home'
'adfd' = '/usr/there'
'ddddd = '/someplace/else'
etc";
and
$x = "
1='strings with blanks or whatever'
2='another set of words'
etc.
Now, how can I get it into _one_ line? The following returns nothing:
%hash = split /\n|\s*=\s*/, $x =~ s/^\s+|\s+$|'//g;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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