Joe Discenza wrote: > [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>* *wrote, on > Mon 1/10/2005 06:53 > > : What I have is > > : > > : $string = “my name is %name%, age %age%, department %dept%”; > > : > > : What I want is > > : > > : The % wrapped text returned to an array like > > : > > : my @list = GetVars($string); > > : > > : Anyone done something similar or know how I could do a regex to return > > : > > : @list = qw (name age dept) > > > What characters can your variable names contain? Are they standard > Perl/C varnames? Here's how you match a varname: > > [_a-zA-Z][_a-zA-Z0-9]* > > If your varnames can look different, adjust that sub-regex in the > regexen below. > > So here's how you get the list of %-wrapped varnames in a string: > > my @list = $string =~ /\%([_a-zA-Z][_a-zA-Z0-9]*)\%/g;
This is more straight forward : my @list = $string =~ /%([^%]+)%/g; > But is what you really want to do to substitute the value of $hash{var} > whenever %var% appears in the string? Then do that the first time: > > $string =~ s/\%([_a-zA-Z][_a-zA-Z0-9]*)\%/$hash{$1}/eg; > > I'm not sure you need to escape the %, but it doesn't hurt; and as > always, not tested ;). -- ,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED] (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff) _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs