SPUG: hash from string

Tim Maher/CONSULTIX tim at consultix-inc.com
Wed Jul 12 22:02:14 CDT 2000


I'm as fond of map() as the next JAPH, but unless I'm missing
something about the problem at hand, I don't see why map(), or
even split(), is needed; it can all be done with capturing parens
and a matching operator:

$x = "
	'xyz' = '/export/home'
	'adfd' = '/usr/there'
	'ddddd' = '/someplace/else'
";

	%hash = $x =~ /'([^']+)'/sg;

Or, if we're unwilling to assume that we've got an
even number of quoted strings:

	%hash = $x =~ /'([^']+)'.+?'([^']+)'/sg;

*========================================================================*
| 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 |
| DAMIAN CONWAY Seminars;  Adv. OO Perl: 7/6,  Parsing with Modules: 7/7 |
*========================================================================*

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