SPUG: hash from string
tim at consultix-inc.com
Fri Jul 14 15:10:08 CDT 2000
On Fri, Jul 14, 2000 at 11:59:26AM -0700, Peter Dueber wrote:
> By george you're right Tim!
> However it doesn't work for the case: digit = 'quoted string'
> 3='something else'
Didn't know that it was supposed to!
But all that would take is a modification to the RE; I initially tried
a solution that did it all with one matching operator, but it was too
complex and ugly, so I'll show you these easier solutions:
'abc' = '/abc/xyz',
2 = '/abc/xyz',
'bac' = '/bac/xyz',
33 = '/c/z'
# pre-process to quote digit strings:
$x =~ s/(\d+)(\s*=)/'$1'$2/g;
# now run original one-liner solution:
%hash = $x =~ /'([^']+)'.+?'([^']+)'/g;
# Or, less "scrutably", using a hightly contrived one-liner:
%hash = (($x =~ s/(\d+)(\s*=)/'$1'$2/g), $x) =~ /'([^']+)'.+?'([^']+)'/g;
| Dr. Tim Maher, CEO, Consultix (206) 781-UNIX/8649; ask for FAX# |
| Email: tim at consultix-inc.com Web: http://www.consultix-inc.com |
| CLASSES: 8/14: UNIX Fund. 8/21: Shell & Utilities 9/11: Perl + Mods |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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